[Django]-Django โ€“ Sort the list into 3 columns on templates

2๐Ÿ‘

โœ…

๐Ÿ‘คarie

2๐Ÿ‘

I did this yesterday.

{% for link in footer_links %}
    {% if forloop.first or forloop.counter0|divisibleby:"6" %}
    <ul>
    {% endif %}
        <li><a href='{{ link.href }}'>{{ link.title }}</a></li>
    {% if forloop.last or forloop.counter|divisibleby:"6" %}
    </ul>
    {% endif %}
{% endfor %}

it doesnโ€™t quite do three columns, but it splits the links up into lists of a certain length (6)

๐Ÿ‘คGlycerine

0๐Ÿ‘

I donโ€™t exactly understand the criteria that is determining your grouping โ€“ is it literally just cycling through by 3? If so, I think that the cycle template tag is what you are looking for:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#cycle

๐Ÿ‘คjMyles

Leave a comment