twig if not empty code example
Example 1: twig is not empty
{% if not (varname is empty) %}
That's not empty.
{% endif %}
Example 2: twig is empty
{% if varname is empty %}
That's empty.
{% endif %}
Example 3: if variable is defined twig
{# defined works with variable names #}
{% if foo is defined %}
...
{% endif %}
{# and attributes on variables names #}
{% if foo.bar is defined %}
...
{% endif %}
{% if foo['bar'] is defined %}
...
{% endif %}