2013-08-21 92 views
1

每个公司对象都与图像具有一对多关系。
现在在我的模板中,我想检查是否有类型testtype的图像。如果条件模板引擎中的for循环条件为

如何处理这与树枝?下面给我一个例外:值 “testtype”

意外令牌 “串”( “名” 预期)

嫩枝

{% for image in company.images if image.type is 'testtype' %} 
{% endfor %} 
+2

您是否尝试过一个简单的'如果image.type ==“testtype''? – SirDerpington

+0

同样的例外:( – user2485214

+1

)你想迭代所有的公司对象还是只有那些'image.type'“testtype”?如果你想迭代所有的对象,只是为'testtype'图像做一个特殊的输出可以把if放在你的for循环中。'{%if image.type =='testtype'%}'应该可以工作 – SirDerpington

回答

-1

你试试这个

{% for myimage in company.images %} 
    {% if myimage.type == 'testtype' %} 
    {% endif %} 
{% endfor %} 
0

只要testtype是一个字符串,那么我会尝试:

{% for image in company.images if image.type == 'testtype' %}