The right way to check for empty content in Twig
Have you ever used {% if content|render|trim is not empty %}
in twig to validate content is not empty? If so, you might end up with some surprises related to the use of the render
method.
Have you ever used {% if content|render|trim is not empty %}
in twig to validate content is not empty? If so, you might end up with some surprises related to the use of the render
method.
In most of the projects we build, the HTML markup provided by core just gets in the way. There is way too many wrapper divs. This can cause issues when trying to create lean markup that matches what is produced in a generated styleguide.
In this post, I'll introduce you to the concept of bare templates, and how you can remove unnecessary markup from your Twig templates.