IF a = = true OR b = = true 语句

我找不到让 TWIG 解读以下 If判断语句的方法:

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

我是漏掉了什么,还是不可能?

204588 次浏览

check this Twig Reference.

You can do it that simple:

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

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 %}