Django Templates - Changing context for an 'include' template

瘦欲@ 提交于 2019-12-03 01:43:01

You can try the with template tag:

{% with table_header1 as table_header %}
{% with table_data1 as table_data %}
    {% include 'default_table.html' %}
{% endwith %}
{% endwith %}

{% with table_header2 as table_header %}
{% with table_data2 as table_data %}
    {% include 'default_table.html' %}
{% endwith %}
{% endwith %}

But I don't know if it works, I didn't try it myself.

Notice: If you have to include this very often, consider to create a custom template tag.

You may use with inside include:

{% include "default_table.html" with table_header=table_header1 table_data=table_data1 %}

See also documentation on include tag.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!