Login

Snippets by cmcavoy

Snippet List

TemplateTag to Split a List into Uniform Chunks

Creates a template tag called "split_list" which can split a list into chunks of a given size. For instance, if you have a list 'some_data', and you want to put it into a table with three items per row, you could use this tag: {% split_list some_data as chunked_data 3 %} Given a some_data of [1,2,3,4,5,6], the context variable 'chunked_data' becomes [[1,2,3],[4,5,6]] This is useful for creating rows of equal numbers of items. Thanks to the users of #django (pauladamsmith, Adam_G, and ubernostrum) for advice and pointers, thanks to Guyon Morée for writing the chunking recipe that this tag is based on.

  • templatetag
  • split
  • list
Read More

cmcavoy has posted 3 snippets.