Jinja2: Create new row for every 3 items

后端 未结 2 1692
天命终不由人
天命终不由人 2021-01-31 04:09

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 04:59

    The best way to do this is to use the built in batch filter to break up your list into groups of three:

    {% for article_row in articles | batch(3, ' ') %}
    
    {% for article in article_row %}
    {{ article }}
    {% endfor %}
    {% endfor %}

提交回复
热议问题