Star
You must be signed in to star a gist
Twig recursive macro
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 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Viel Dank, Mercy