[Django]-Django Templates – Changing context for an 'include' template

36πŸ‘

βœ…

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.

πŸ‘€Felix Kling

77πŸ‘

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.

πŸ‘€zag

Leave a comment