IF a == true OR b == true statement

前端 未结 2 956
不思量自难忘°
不思量自难忘° 2021-02-01 11:42

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 missi

相关标签:
2条回答
  • 2021-02-01 12:33

    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 %}
    
    0 讨论(0)
  • 2021-02-01 12:36

    check this Twig Reference.

    You can do it that simple:

    {% if (a or b) %}
        ...
    {% endif %}
    
    0 讨论(0)
提交回复
热议问题