Issue
I'm trying to include a .html using
{% include "paintings/experiments/points/{{substance.name}}.html" %}
This however leads to the error TemplateDoesNotExist
.
If I hardcode the name of the .html file, it does work.
{% include "paintings/experiments/points/fabric.html" %}
And, in fact, I can use {{substance.name}}
inside the included html, were it does indeed get substituted for fabric
. Why can I not use a django variable when using an include tag?
Solution
I doit with the add
templateTag.
{% include "paintings/experiments/points/"|add:substance.name %}
Notice that substance.name
should have .html
. I'm using this approach to use dynamic Templates. So in a context_processor
I set the variable value and use it normally, like this:
{% include ""|add:paginationTemplatePath with page=page_obj %}
In this case, I change the paginationTemplatePath
given certain conditions on the context_processor
.
I'm exposing this example in order to enrich the answer for other cases, as use include with variable page
.
Answered By - titusfx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.