Skip to content

Instantly share code, notes, and snippets.

@umkasanki
Created May 28, 2021 14:59
Show Gist options
  • Save umkasanki/191358c50bfe729a88c7a56a9d84ef50 to your computer and use it in GitHub Desktop.
Save umkasanki/191358c50bfe729a88c7a56a9d84ef50 to your computer and use it in GitHub Desktop.
Craft CMS. Categories tree
<div>
{% for category in craft.categories.all() %}
{% if category.level == 1 %}
{% set children = category.getChildren() %}
<h4>{{ category.title }}</h4>
{% if children|length %}
<ul>
{% for subcategory in children %}
<li>{{ subcategory.title }}</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
{% endfor %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment