I am already trying to concatenate like this:
{% for choice in choice_dict %}
{% if choice =='2' %}
{% with "mod"|add:forloop.counter|add:".html" as template %}
{% include template %}
{% endwith %}
{% endif %}
{% endfor %}
but for some reason I am only getting "mod.html" and not the forloop.counter number. Does anyone have any idea what is going on and what I can do to fix this issue? Thanks alot!
You probably don't want to do this in your templates, this seems more like a views job: (use of if within a for loop).
Then pass
chosen_templates
to your template where you will have onlyAlso, I don't quite understand why you are using a dict to select the template with a number that is not in the dictionnary.
for key,value in dict.items()
may be what you are looking for.Try without using the block "with"
Your problem is that the forloop.counter is an integer and you are using the
add
template filter which will behave properly if you pass it all strings or all integers, but not a mix.One way to work around this is:
which results in:
The second with tag is required because stringformat tag is implemented with an automatically prepended
%
. To get around this you can create a custom filter. I use something similar to this:http://djangosnippets.org/snippets/393/
save the snipped as some_app/templatetags/some_name.py
in template: