-
-
Save garak/0c7cc873c70c09863641401981f81442 to your computer and use it in GitHub Desktop.
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
You are a life saver, bro.