Search code examples
shopware6

Insert subcategories inside Shopware6 custom block


I have created a custom block that i use inside "listing page" using this guide https://developer.shopware.com/docs/v/6.4/guides/plugins/plugins/content/cms/add-cms-block.

I want to display in this block a list all subcategories of the current category. so a created a text block and i am trying to populate it with subcategories looking for the right variable to pick using {{dump()}}.

The problem is that i don't know how to pick the current category variable and his children, looking in documentation i can't find the solution.


Solution

  • You can use the navigation property using the header accessor of the page to find the currently active category and get its children.

    {% set currentCategoryId = page.header.navigation.active.id %}
    {% set currentCategoryChildren = page.header.navigation.getChildren(currentCategoryId).tree %}
    {{ dump(currentCategoryChildren) }}