Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Category filter for Craft Cms searchit plugin. Takes nesting of categories into account. More information on http://craftsnippets.com/articles/filtering-entries
{% set handle = 'category_handle' %}
{% for category in craft.categories.group(handle).all() %}
{% set line = '' %}
{% set depth = category.getAncestors()|length %}
{% for number in range(0, depth) %}
{% set line = line ~ '=' %}
{% endfor %}
{{ ({
filter: {
relatedTo: category.id
},
label: line ~ ' ' ~ category.title
})|json_encode() }}{{ not loop.last ? ',' }}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.