Archive for May, 2013

Not Defined and Not Empty/Null in Twig

Wednesday, May 1st, 2013

Long time no write.  Came across some syntax today that solves an old annoyance in Symfony's Twig.

Rather than blather on in code with the following complex statement to make sure that a value is both defined and not null:

{% if var is defined and var is not null %}

one can instead simply do this:

{% if var|default is not empty %}

or even more simply:

{% if var|default %}