Skip to content

Instantly share code, notes, and snippets.

@vasilukwolf
Forked from tentacode/list.html.twig
Created September 7, 2017 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasilukwolf/08785940bea6040239714a0c615e4098 to your computer and use it in GitHub Desktop.
Save vasilukwolf/08785940bea6040239714a0c615e4098 to your computer and use it in GitHub Desktop.
Twig recursive macro
{% 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