Skip to content

Instantly share code, notes, and snippets.

@dajare
Created May 6, 2020 09:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dajare/af681eeb5f9c8134f9ece45cc2067b87 to your computer and use it in GitHub Desktop.
Twig macro to generate navigation tree
<!-- Nav -->
<nav id="nav">
{% macro tree(parent) %}
{% import _self as utils %}
{% for child in parent.children %}
{% if child.page and not child.page.hidden %}
<li><a href="{{ child.page.url }}">{{ child.page.title }}</a>{% endif %}
{% if child.children and not child.page.hidden %}<ul>
{{ utils.tree(child) }}
</ul>{% endif %}</li>
{% endfor %}
{% endmacro %}
<ul id="pagetree">
<li><a href="{{ pages["index"].url }}">{{ pages["index"].title }}</a></li>
{% import _self as utils %}
{{ utils.tree(pages["index"].tree_node) }}
</ul>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment