2013-06-27 196 views
1

我怎樣才能插入此:在與包括標籤包括標籤

<strong>{% trans "Error!" %}</strong> {% trans "blablabla." %} 

而是 「XXX」 在這裏:

{% include "alert.html" with connotation="error" message="xxx" %} 

請指教。

+0

你到目前爲止做了什麼? – zmo

+1

你不能。爲了實現它,您可以修改'alert.html'模板以有條件地顯示您想要傳遞的塊,例如'{%if message%} .. block goes here .. {%endif%}' – J0HN

回答

0

據我所知,除非在視圖中創建完整的消息並將其作爲模板上下文參數傳遞,否則不能這麼做。

而不是傳遞完整的消息,我會建議通過一些錯誤代碼,並基於那在"alert.html"顯示適當的消息。

所以,你的包含語句將變成這樣的事情:

{% include "alert.html" with connotation="error" error_code=err_code %} 

和內部alert.html,你可以把條件顯示相應的消息。

{% if error_code == "404" %} 
    <strong>{% trans "Not Found!" %}</strong> 
{% endif %}