Create category navigation


Is there any possibility to create a dynamic category navigation based on a root category?
We’ve an api to import category from the customer erp-system. To show them in the frontend we also have to create a navigation for that.

My hope is, that there is any “logic” to create an navigation point with an option like “show recursively all child categories”.



Hi Mike,

what you can do is introducing a new type to the navigation like “categoryTree” and implement it as a new block in the template e.g.
{% block categoryTree %} <li class="c-nav-list__item {% if isCurrent %} is-open{% endif %}{{ class }}"> <nav> <span class="c-nav-list__toggle{% if isCurrent %} is-open{% endif %}"></span> {% include '@Application/layout/navigation/_partials/category-nodes.twig' with {categoryNodes: categories, nested: true} %} </nav> </li> {% endblock %}

To make sure, that you can input it in backend, extend the NavigationNodeFormType with the new Type as choices:
const NODE_TYPE_CATEGORY_TREE = 'category_tree';
and override the
protected function addNodeTypeField(FormBuilderInterface $builder)
with the new type.

Hope that works for you.