swig-template

Test for empty variable in Swig template


In Twig I have operator is and test for empty variable (string or array):

{% if info is empty %}
    ...
{% endif %}

How I can do something like this in Swig template?


Solution

  • Simply do

    {% if !info.length %}
    ...
    {% endif %}
    

    This will match strings (""), arrays ([]) and any other object which doesn't have a .length property with truthy value.