I have the following code in my template
{% set counter = 0 %}
{% for object in object_list %}
{% if object.attr1 == list1.attr1 and object.attr2 = list2.attr2 %}
<li><a href="{{ object.get_absolute_url }}"> Link {{counter++}} </a></li>
{% endif %}
{% endfor %}
I setting the value of a variable using this custom tag and what I want to do is to increment the value only if the if
loop is satisfied. I know {{counter++}}
does not work. But how can I write a custom tag that would do the same task?