Navigation
Basics
Pimcore comes with a standard navigation implementation in the form of a Twig extension. It builds a navigation container based on the existing document structure. The process of rendering is divided into 2 steps:
- Build the navigation:
{% set nav = pimcore_build_nav({active: activeDocument, root: navigationRootDocument}) %}
- Render the navigation:
pimcore_render_nav(nav)
orpimcore_nav_renderer('menu').render(nav)
The building step does not necessarily need to happen in the view script. In fact the view helper just forwards the
build()
call to thePimcore\Navigation\Builder
service. You can also build the navigation in your controller or a service and pass the navigation object to the view.
Only documents are included in this structure, Folders are ignored, regardless of their navigation properties.
{# get root node if there is no document defined (for pages which are routed directly through static route) #}
{% if not document is defined or not document %}
{% set document = pimcore_document(1) %}
{% endif %}
{# get the document which should be used to start in navigation | default home #}
{% set navStartNode = document.getProperty('navigationRoot') %}
{% if not navStartNode is instanceof('\\Pimcore\\Model\\Document\\Page') %}
{% set navStartNode = pimcore_document(1) %}
{% endif %}
{% set mainNavigation = pimcore_build_nav({
active: document,
root: navStartNode
}) %}
{# later you can render the navigation #}
{{ pimcore_render_nav(mainNavigation) }}
Having set up the navigation container as shown above, you can easily use it to render a navigation tree, menus, or breadcrumbs.