一个接受多个模板名称的 `{% include %}` 版本。
项目描述
一个接受多个模板名称的 `{% include %}` 版本。
用法
将 `multiple_include` 添加到 `INSTALLED_APPS`。
然后,在您的模板中
{% load multiple_include %}
{% multiple_include "template1.html" "template2.html" "template2.html" with object=item %}
这个模板标签将包含列表中第一个存在的模板。这允许更有趣的使用
{% load multiple_include %}
{% with "story_"|add:object.category_slug|add:".html" as category_template %}
{% multiple_include category_template "news/story_default.html" %}
{% endwith %}
注意:为了更干净的字符串连接,您可以使用随 `Django Basic Apps` 一起提供的 `capture` 标签
在您的设置中
INSTALLED_APPS += ('basic.tools')
模板
{% load multiple_include capture %}
{% capture as category_template %}
story_{{ object.category_slug}}.html
{% endcapture %}
{% multiple_include category_template "news/story_default.html" %}