{% include "example.html" with name="John" hide_last_name=True %}
Basically, I am trying to include "example.html" as a sub-template in my main template. Additional context is provided with the mean of passing the keyword arguments name
and hide_last_name
. While the django template system has no trouble recognize name
, it somehow just can't recognize hide_last_name
. I suspect the use of boolean keyword argument in Include
tag is now allowed but then I can't find anywhere in the official docs mentions that. Please help out. Thanks.
For Django <= 1.4.x
As said before, Django tries to find a variable named "True". The simplest way to handle this is to use an integer value, which will not be evaluated.
You could write in the includer template
{% include "example.html" with show_last_name=1 %}
and in the included template
John
{% if show_last_name %}
Doe
{% endif %}
For Django >= 1.5
You can use True and False in templates, so this is no longer a issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With