1👍
✅
First, You can not use double asterisks in include
tag. include
tag’s with
parameter only understands foo=1
or 1 as foo
notations.
So, you have three options:
1) Included template will have all variables available from top level template. Main con: timewindow.html
and search_box.html
can’t have same variable with different values.
def my_view(request):
extra_templates=[
{'path': 'dashboard/timewindow.html'},
{'path': 'dashboard/search_box.html'},
]
context = {'extras': extra_templates, 'var': 23}
return render(request, 'dashboard/base.html', context)
2) Use prefix
{# parent template #}
{% for extra_template in extras %}
{% include extra_template.path with extra=extra_template.context %}
{% endfor %}
{# included template #}
{{ extra.var }}
3) Write custom template tag and expand context by yourself
Source:stackexchange.com