Created
July 27, 2014 14:08
-
-
Save tacone/8f270be8814c107399e5 to your computer and use it in GitHub Desktop.
Print a Baum tree with Twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maxdepth is not mandatory