Pergunta

I can't find a way to have TWIG interpret the following conditional statement:

{% if a == true or b == true %}
do stuff
{% endif %}

Am I missing something or it's not possible?

Foi útil?

Solução

check this Twig Reference.

You can do it that simple:

{% if (a or b) %}
    ...
{% endif %}

Outras dicas

Comparison expressions should each be in their own brackets:

{% if (a == 'foo') or (b == 'bar') %}
    ...
{% endif %}

Alternative if you are inspecting a single variable and a number of possible values:

{% if a in ['foo', 'bar', 'qux'] %}
    ...
{% endif %}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top