defined

The defined test checks to see if a variable is defined in the current context.

Examples

Test to see if a variable is defined.

{% if foo is defined %}
   ...
{% endif %}

Test a variable attribute or an array key value

{% if foo.bar is defined %}
   ...
{% endif %}

{% if foo['bar'] is defined %}
   ...
{% endif %}

 Negative test

{% if foo is not defined %}
   ...
{% endif %}

< Back to the list of tests