-
-
Save vasilukwolf/08785940bea6040239714a0c615e4098 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) %} | |
<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