I'm looking for a way to use something like the modulus operator in django. What I am trying to do is to add a classname to every fourth element in a loop.
With modulus it would look like this:
{% for p in posts %}
<div class="post width1 height2 column {% if forloop.counter0 % 4 == 0 %}first{% endif %}}">
<div class="preview">
</div>
<div class="overlay">
</div>
<h2>p.title</h2>
</div>
{% endfor %}
Of course this doesn't work because % is a reserved character. Is there any other way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…