I\'m creating a catalogue, where there is a list of items of undefined length. I want to spit it out in rows with three columns each. So I have the following html:
You could try to create a custom template filter, that would return a list of list of 3-items.
Quick attempt :
@register.filter
def splitByThree(data):
return [l[i:i+3] for i in range(0, len(l), 3)]
And then in your template :
{% load splitByThree %}
{% for list in data|splitByThree %}
{% for item in list %}
{{ item }}
{% endfor %}
{% endfor %}