Skip to content

Instantly share code, notes, and snippets.

@garak
Forked from tentacode/list.html.twig
Last active July 18, 2020 05:50
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save garak/0c7cc873c70c09863641401981f81442 to your computer and use it in GitHub Desktop.
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 %}
@akilshadi
Copy link

Viel Dank, Mercy

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