Skip to content

Instantly share code, notes, and snippets.

@tacone
Created July 27, 2014 14:08
Show Gist options
  • Save tacone/8f270be8814c107399e5 to your computer and use it in GitHub Desktop.
Save tacone/8f270be8814c107399e5 to your computer and use it in GitHub Desktop.
Print a Baum tree with Twig
{% macro menuLinks(root, maxdepth) %}
{% import _self as macros %}
{# print a UL tree #}
{% for link in root.children %}
<li>
<a href="{{ link.slug }}">{{ link.name }}</a>
{% if link.children and (maxdepth > link.depth or not maxdepth) %}
<ul>
{{ macros.menuLinks(link, maxdepth) }}
</ul>
{% endif %}
</li>
{% endfor %}
{% endmacro %}
@tacone
Copy link
Author

tacone commented Jul 27, 2014

maxdepth is not mandatory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment