带有等号的TwigAND运算符
在我的 Symofny 项目中,我正在为具有特定状态的实体显示按钮。
如果我只为一种状态定义它可以工作,但是当我尝试使用两种状态时它不会。但它适用于如果我把例如' !='。
{% if (item.status == 'free') and (item.status == 'paid') %}
<a type="button" href="{{ path('my_path', {'id':item.id}) }}">Btn</a>
{% endif %}
也same as按照树枝文档中的描述进行了尝试。
回答
解决此问题的另一种方法是使用数组和in运算符
{% if item.status in [ 'free', 'paid', ] %}
{% endif %}