Thi*_*Lam 3 django django-templates
我有一些静态文本需要显示在模板中的2个位置.
例如:
<div>
{% if something %}
This is a static text
{% else %}
Something else happened
{% endif %}
</div>
... more html
<span>
{% if something %}
This is a static text
{% else %}
Something else happend
{% endif %}
</span>
Run Code Online (Sandbox Code Playgroud)
include template但这可能不是实现我的目标的最佳方式.最好的方法是什么?
绝对使用包含标签:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags
标签文件要么是超级简单的,就像文本"这是一个静态文本"或整个块一样:
{% if something %}
This is a static text
{% else %}
Something else happened
{% endif %}
Run Code Online (Sandbox Code Playgroud)
"something"可以作为变量传递给模板标记,因此您可以以可变的方式使用整个块.
| 归档时间: |
|
| 查看次数: |
940 次 |
| 最近记录: |