Skip to main content
The bundle registers three Twig functions via MenuExtension.

dashboard_menu_tree

Loads and returns the menu tree for a given menu code.
dashboard_menu_tree(menuCode, permissionContext?, contextSets?)
Returns: list<array{item: MenuItem, children: list<array>}> Each entry in the returned list is an associative array with two keys:
  • item — the MenuItem entity
  • children — a recursively structured list of the same shape
Only items that pass the configured MenuPermissionCheckerInterface are included. Parents whose children are all hidden are automatically pruned from the tree.

Parameters

menuCode
string
required
The menu code hint (e.g. sidebar). Passed through MenuCodeResolverInterface, so the resolved code may differ from the hint.
permissionContext
mixed
default:"null"
Context value passed to MenuPermissionCheckerInterface::canView(). When null (or omitted), the current Request object is used as the context automatically.
contextSets
array | null
default:"null"
Ordered list of context objects for resolving which menu variant to use. Each element is either an associative array of key-value pairs (e.g. {'partnerId': 1}) or null to match the context-free menu. The first matching menu is used. When null or omitted, default resolution (no context filtering) is applied.

Usage

{# Basic usage — current locale, current request as permission context #}
{% set tree = dashboard_menu_tree('sidebar') %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with { menuTree: tree, menuCode: 'sidebar' } %}
{# With context sets — resolve a partner/operator-specific variant #}
{% set contextSets = [{'partnerId': 1, 'operatorId': 42}, {'partnerId': 1}, {}] %}
{% set tree = dashboard_menu_tree('sidebar', null, contextSets) %}
{# Iterating the tree manually #}
{% set tree = dashboard_menu_tree('sidebar') %}
{% for node in tree %}
  <a href="{{ dashboard_menu_href(node.item) }}">{{ node.item.label }}</a>
  {% for child in node.children %}
    <a href="{{ dashboard_menu_href(child.item) }}">{{ child.item.label }}</a>
  {% endfor %}
{% endfor %}

dashboard_menu_config

Returns the render configuration for a menu. Use this when you need CSS classes, depth limit, icon settings, or collapsible behaviour in a custom template.
dashboard_menu_config(menuCode, contextSets?)
Returns: array with the following keys:

Parameters

menuCode
string
required
The menu code hint. Resolved through MenuCodeResolverInterface the same way as in dashboard_menu_tree.
contextSets
array | null
default:"null"
Ordered list of context objects for variant resolution. Same semantics as in dashboard_menu_tree.

Return value

classes
object
CSS class strings keyed by element name (e.g. menu, item, link, children). Values come from the Menu entity configuration.
ul_id
string | null
HTML id attribute to apply to the root <ul> element. null when not set.
item_span_active
boolean
When true, the template wraps item content in an additional <span> element for active-state styling. Controlled by global bundle configuration.
item_span_class
string
CSS class applied to the item content <span> when item_span_active is true. Defaults to d-flex align-items-center flex-nowrap.
icon_size
string
Icon size value (CSS length, e.g. 1em). Passed to the icon rendering helper. Defaults to 1em.
depth_limit
integer | null
Maximum depth to render. The template stops recursing below this level. null means unlimited.
icons
object
Icon rendering settings.
collapsible
boolean
When true, the entire menu is wrapped in a collapsible block with a toggle button. Configured on the Menu entity.
collapsible_expanded
boolean
Initial expanded state when collapsible is true.
nested_collapsible
boolean
When true, individual items with children render a chevron to expand/collapse their nested list.
menu_name
string | null
Human-readable name of the resolved menu. null when not set.

Usage

{# Passing config explicitly to the template #}
{% set tree = dashboard_menu_tree('sidebar') %}
{% set config = dashboard_menu_config('sidebar') %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with {
    menuTree: tree,
    menuCode: 'sidebar',
    menuConfig: config
} %}
{# Omitting menuConfig — the template resolves it internally #}
{% set tree = dashboard_menu_tree('sidebar') %}
{% include '@NowoDashboardMenuBundle/menu.html.twig' with { menuTree: tree, menuCode: 'sidebar' } %}
{# Accessing individual config values in a custom template #}
{% set config = dashboard_menu_config('sidebar') %}
<ul id="{{ config.ul_id }}" class="{{ config.classes.menu ?? '' }}">
  {# ... #}
</ul>

dashboard_menu_href

Generates a URL string from a MenuItem object.
dashboard_menu_href(item, referenceType?)
Returns: string

Parameters

item
MenuItem
required
A MenuItem entity, as received from the item key inside a dashboard_menu_tree node.
referenceType
integer
default:"0"
Symfony UrlGeneratorInterface reference type constant:
  • 0ABSOLUTE_PATH (default): returns /path/to/page
  • 1ABSOLUTE_URL: returns https://example.com/path/to/page
  • 2RELATIVE_PATH: returns a relative URL
  • 3NETWORK_PATH: returns //example.com/path/to/page
For external URL items the stored URL is returned as-is regardless of this parameter.

Usage

{# Default — absolute path #}
<a href="{{ dashboard_menu_href(node.item) }}">{{ node.item.label }}</a>

{# Absolute URL (e.g. for use in emails or meta tags) #}
<a href="{{ dashboard_menu_href(node.item, 1) }}">{{ node.item.label }}</a>