Skip to content

Instantly share code, notes, and snippets.

@tyssen
Created October 17, 2023 00:04
Show Gist options
  • Save tyssen/fb4ef35da93ebee1f5c8ac1abe388027 to your computer and use it in GitHub Desktop.
Save tyssen/fb4ef35da93ebee1f5c8ac1abe388027 to your computer and use it in GitHub Desktop.
Craft categories
{% set props = {
categories: props.categories.all() ??? null
} %}
{% set selectedCategories = props.categories %}
{# {% dd selectedCategories %} #}
{% set leafCategories = selectedCategories|filter(
category => selectedCategories|filter(current => category.isAncestorOf(current)) is empty
) %}
{# {% dd leafCategories %} #}
{% set products = craft.entries.section('products').relatedTo(leafCategories).all() %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment