{% set items = namespace(sections=[], pages=[]) %} {# sort children into pages and sections #} {% for item in nav %} {% if item.is_section %} {% set items.sections = items.sections + [item] %} {% elif item != page %} {% set items.pages = items.pages + [item] %} {% endif %} {% endfor %} {# add heading #}
{% for item in items.pages %}{% endif %} {# add sections #} {% for item in items.sections %}{{ item.title }} {% endfor %}
{% for subitem in item.children %} {# use a namespace so that we can set stuff within a sub-for loop #} {% set index = namespace(obj=subitem) %} {# if subitem is a section, navigate to its index page #} {% if subitem.is_section %} {% for child in subitem.children if child.is_index %} {% set index.obj = child %} {% endfor %} {% endif %} {# create list item #} {% if subitem != item.children[0] %}{% endfor %}{{ index.obj.title }} {% endif %} {% endfor %}