Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 720 Bytes

filter_chunk.rst

File metadata and controls

21 lines (15 loc) · 720 Bytes

django

This filter splits a list in shorter lists. It splits an array in sub-arrays of at most a given length. This is useful when displaying a list of items in columns or rows.

For example:

{% for s in [1,2,3,4,5]|chunk:2 %}
    {% for n in s %}{{ n|format_number }} {% endfor %} * 
{% endfor %}

This displays 1 2 * 3 4 * 5 *, as the array is split in three chunks. The last chunk is not filled to the maximum length. Then number of chunks depends on the length of the input list, this in contrary to the split_in filters where the number of splits is fixed and the length per split is variable.

filter-split_in, filter-vsplit_in