Reputation: 37934
I have many icons, with names icon1, icon2, icon3 and so on... which are coming from server
how can I make a forloop and set that iconNUMBER
in a loop automatically?.
I tried this:
{% for i in "1234" %}
{{icon}}{{forloop.counter}}
{% endfor %}
but this is not giving me what I want. why cannot I do something like this:
{{ icon{{forloop.counter}} }},
but this is giving me error, saying it cannot parse the expression
Upvotes: 0
Views: 46
Reputation: 43265
I guess you are looking for concatenation of your icon
variable and for loop counter.
{% for i in "1234" %}
{% with c=forloop.counter|stringformat:"s" %}
{{icon|add:c}}
{% endwith %}
{% endfor %}
Upvotes: 3