[Answer]-Translating a "flat" list to nested HTML unordered lists

1👍

Use regroup tag:

<label>Food</label>
{% regroup foods by category as category_list %}
<ul>
{% for category in category_list %}
    <li>
        <label>{{ category.grouper }}</label>
        <ul>
        {% for food in category.list %}
            <li>{{ food.name }}</li>
        {% endfor %}
        </ul>
    </li>
{% endfor %}
</ul>

Leave a comment