Luk*_*kas 2 php templates conditional-statements twig
我需要在树枝中设置一些条件,所以我有这个:
{% if app.session.get('campaignVersion') is not null and is not '4.4d'}
...
{% elseif app.session.get('campaignVersion') is null or '4.4d' %}
...
{% endif %}
Run Code Online (Sandbox Code Playgroud)
但是我有语法和逻辑错误,也许它必须有一个标准运算符,例如!=
,我做错了什么?谢谢你的帮助。
Twig 不是人类语言解释器 :-)
Twig 无法隐含地知道谁是 中的主题and is not '4.4d'
。
尝试:
{% if app.session.get('campaignVersion') is not null and app.session.get('campaignVersion') != '4.4d' %}
Run Code Online (Sandbox Code Playgroud)
或者为了更好的可读性:
{% if app.session.get('campaignVersion') not in [null, '4.4d'] %}
Run Code Online (Sandbox Code Playgroud)