Last active
February 28, 2019 22:43
-
-
Save piotrpog/b6c9d08097143d680775438c39200e98 to your computer and use it in GitHub Desktop.
Category filter for Craft Cms searchit plugin. Takes nesting of categories into account. More information on http://craftsnippets.com/articles/filtering-entries
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
{% 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