2013-08-21 90 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' %}