title: Django Template - Increment the value of a variable
body: <p>I have the following code in my template</p>
  
  <pre><code>{% set counter = 0 %}
  {% for object in object_list %}
      {% if object.attr1 == list1.attr1 and object.attr2 = list2.attr2 %}
          &lt;li&gt;&lt;a href="{{ object.get_absolute_url }}"&gt; Link {{counter++}} &lt;/a&gt;&lt;/li&gt;
       {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>I setting the value of a variable using this <a href="http://www.soyoucode.com/2011/set-variable-django-template">custom tag</a> and what I want to do is to increment the value only if the <code>if</code> loop is satisfied. I know <code>{{counter++}}</code> does not work. But how  can I write a custom tag that would do the same task?</p>