I would like to change the class attribute of an li after each 4 elements (that means 5th, 9th, 13th li element classes should be changed).
I have tried something like below but it gave me an syntax error:
Could not parse the remainder: ‘%4’ from ‘forloop.counter%4’
{% for p in plist %}
{% ifequal forloop.counter%4 1 %}
<li class="clear"> {{p.title}} </li>
{% else %}
<li> {{p.title}} </li>
{% endifequal %}
{% endfor %}
I will appreciate if somebody will suggest me a working solution.
You can’t do evaluations like that in the django template. The ifequal tag expects only two parameters, and compares them. You would need some type of filter.
However, you could use the cycle tag instead:
EDIT: As pointed out, the original solution cleared the 4, 8th, etc, instead of from the 5th onwards. I have updated the answer to include the changes by Tolga.