Skip to content

Instantly share code, notes, and snippets.

@piotrpog
Last active February 28, 2019 22:43
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 piotrpog/b6c9d08097143d680775438c39200e98 to your computer and use it in GitHub Desktop.
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
{% 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