我在我的一个模板中执行此操作:
注意:我可能会有更多字段进入{% if activite.travel %}
{% with activite.travel.personne as personne %}
{% include 'includes/person_detail.html' %}
{% endwith %}
{% endif %}
{% if activite.relation %}
{% with activite.relation.src as personne %}
{% include 'includes/person_detail.html' %}
{% endwith %}
{% endif %}
,这就是为什么我没有做到" activite
"但是两个单独的" else
"。
我想做类似的事情:
if
有没有办法在模板中执行 ?
答案 0 :(得分:2)
不完全......但您可以在include
中使用with
{% if activite.travel %}
{% include 'includes/person_detail.html' with personne=activite.travel.personne %}
{% elif activite.relation %}
{% include 'includes/person_detail.html' with personne=activite.relation.src %}
{% endif %}