Currently for every article in articles a new div with class span4 is created. Instead for each row I would like to limit it\'s content to three span\'s and create a new row on
You can use loop.index0
and loop.last
inside the for
loop. Here is the for-loop documentation.
Example:
{% extends "base.html" %}
{% block content %}
{% for article in articles %}
{% if loop.index0 % 3 == 0 %}
{% endif %}
...
{% if loop.index0 % 3 == 2 or loop.last %}
{% endif %}
{% endfor %}
{% endblock %}
The Another alternative would be to group the items into rows before passing them into the template, then you can just issue two for-loops one inside the other.loop.last
clause should close the last row even if there were less than 3 items. loop.index0
gives 0 as the remainder and should end when 2 is the remainder