每个公司对象都与图像具有一对多关系。
现在在我的模板中,我想检查是否有类型testtype的图像。如果条件模板引擎中的for循环条件为
如何处理这与树枝?下面给我一个例外:值 “testtype”
意外令牌 “串”( “名” 预期)
嫩枝
{% for image in company.images if image.type is 'testtype' %}
{% endfor %}
每个公司对象都与图像具有一对多关系。
现在在我的模板中,我想检查是否有类型testtype的图像。如果条件模板引擎中的for循环条件为
如何处理这与树枝?下面给我一个例外:值 “testtype”
意外令牌 “串”( “名” 预期)
嫩枝
{% for image in company.images if image.type is 'testtype' %}
{% endfor %}
你试试这个
{% for myimage in company.images %}
{% if myimage.type == 'testtype' %}
{% endif %}
{% endfor %}
<ul>
{% for user in users if user.active %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
http://twig.sensiolabs.org/doc/tags/for.html#adding-a-condition
只要testtype
是一个字符串,那么我会尝试:
{% for image in company.images if image.type == 'testtype' %}
您是否尝试过一个简单的'如果image.type ==“testtype''? – SirDerpington
同样的例外:( – user2485214
)你想迭代所有的公司对象还是只有那些'image.type'“testtype”?如果你想迭代所有的对象,只是为'testtype'图像做一个特殊的输出可以把if放在你的for循环中。'{%if image.type =='testtype'%}'应该可以工作 – SirDerpington