Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Twig recursive macro
{% macro recursiveCategory(category) %}
{% import _self as self %}
<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 %}
{% from _self import recursiveCategory %}
{% if categories %}
<div id="categories">
<ul>
{% for category in categories %}
{{ recursiveCategory(category) }}
{% endfor %}
</ul>
</div>
{% endif %}
@charafsalmi
Copy link

charafsalmi commented Mar 3, 2017

You are a life saver, bro.

@akilshadi
Copy link

akilshadi commented May 28, 2018

Viel Dank, Mercy

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