Skip to content

Instantly share code, notes, and snippets.

@dimd13
Forked from tentacode/list.html.twig
Created April 4, 2017 11:16
Show Gist options
  • Save dimd13/f3583cd16ca48e155e1cdce207f168de to your computer and use it in GitHub Desktop.
Save dimd13/f3583cd16ca48e155e1cdce207f168de to your computer and use it in GitHub Desktop.
Twig recursive macro
{% macro recursiveCategory(category) %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ _self.recursiveCategory(child) }}
{% endfor %}
</ul>
{% endif %}
</li>
{% endmacro %}
{% if categories %}
<div id="categories">
<ul>
{% for category in categories %}
{{ _self.recursiveCategory(category) }}
{% endfor %}
</ul>
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment