Skip to main content
The bundle registers three Twig functions and one Twig filter. Together they let you load a menu tree, read its render config, generate item URLs, and resolve icon names — all from your templates.

dashboard_menu_tree

Returns the menu tree as a nested array, filtered by permissions and decorated with current-route information.
dashboard_menu_tree(menuCode, permissionContext?, contextSets?)
ParameterTypeDescription
menuCodestringMenu code (e.g. 'sidebar'). Resolved through MenuCodeResolverInterface before the DB lookup.
permissionContextmixedOptional value passed to your MenuPermissionCheckerInterface. Defaults to the current Request.
contextSetsarray|nullOrdered list of context objects for multi-tenant resolution. See Context sets.
Return type: list<array{item: MenuItem, children: list<array>}> Each node is an array with:
  • item — the MenuItem entity
  • children — nested nodes (same structure, recursively)
  • isCurrenttrue when this item’s route matches the current request
  • hasCurrentInBranchtrue when any descendant is the current item
Items that fail the permission check are excluded. Parents (and section headers) with no visible children are pruned automatically.

dashboard_menu_config

Returns the render configuration for a menu — CSS classes, icon settings, collapsible flags, and more.
dashboard_menu_config(menuCode, contextSets?)
ParameterTypeDescription
menuCodestringMenu code (resolved the same way as in dashboard_menu_tree).
contextSetsarray|nullOrdered list of context objects.
Return type: array with the following keys:
KeyTypeDescription
classesarray<string, string>CSS classes: menu, item, link, children, section_label, class_current, class_branch_expanded, class_has_children, class_expanded, class_collapsed.
ul_idstring|nullHTML id attribute for the root <ul>.
item_span_activeboolWhen true, non-section items are wrapped in an extra <span>.
item_span_classstringCSS class(es) for the optional item wrapper <span>.
icon_sizestringCSS size for icons (e.g. '1em', '16px').
depth_limitint|nullMaximum depth to render. null = unlimited.
iconsarray{enabled: bool, use_ux_icons: bool, default: string|null}Icon rendering options.
collapsibleboolWrap the menu in a collapsible block with a toggle button.
collapsible_expandedboolWhether the collapsible block starts open.
nested_collapsibleboolGive each item with children its own collapse toggle.
menu_namestring|nullHuman-readable name used as the collapsible toggle label.

dashboard_menu_href

Generates the URL for a MenuItem.
dashboard_menu_href(item)
ParameterTypeDescription
itemMenuItemThe item entity from the tree node.
Return type: string How URLs are built:
  • For items with a route name, the URL is generated from that route and its stored parameters.
  • If the route requires path parameters not stored on the item (e.g. id, slug), the bundle fills them from the current request’s route parameters automatically, so links stay in the same context (e.g. the same entity).
  • On URL generation failure, an error is added to the Symfony flash bag and an empty string is returned.

dashboard_menu_icon_name filter

A Twig filter that converts a full icon library name to the short prefix expected by ux_icon(), using the icon_library_prefix_map configuration.
{{ 'bootstrap-icons:house' | dashboard_menu_icon_name }}
{# outputs: bi:house (with bootstrap-icons: bi in config) #}
The bundle applies this conversion automatically inside menu.html.twig; you only need the filter if you are rendering icons in a custom template.

Usage examples

Basic rendering

The simplest way to render a menu — pass the tree and let the template resolve the config itself:
{% set tree = dashboard_menu_tree('sidebar') %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with { menuTree: tree, menuCode: 'sidebar' } %}
When menuConfig is omitted, the included template calls dashboard_menu_config(menuCode) internally.

Explicit config

Pass menuConfig explicitly when you need to inspect or override config values before rendering:
{% set tree = dashboard_menu_tree('sidebar') %}
{% set menuConfig = dashboard_menu_config('sidebar') %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with {
    menuTree: tree,
    menuCode: 'sidebar',
    menuConfig: menuConfig
} %}
{% set tree = dashboard_menu_tree('sidebar') %}
{% for node in tree %}
    <a href="{{ dashboard_menu_href(node.item) }}">{{ node.item.label }}</a>
{% endfor %}

With a permission context

{% set tree = dashboard_menu_tree('sidebar', app.user) %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with { menuTree: tree, menuCode: 'sidebar' } %}

With context sets (multi-tenant)

See Context sets for full details.
{% set contextSets = [{ 'partnerId': 1, 'operatorId': 1 }, { 'partnerId': 1 }, {}] %}
{% set tree = dashboard_menu_tree('sidebar', null, contextSets) %}
{% set menuConfig = dashboard_menu_config('sidebar', contextSets) %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with {
    menuTree: tree,
    menuCode: 'sidebar',
    menuConfig: menuConfig
} %}