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.
Returns the menu tree as a nested array, filtered by permissions and decorated with current-route information.
dashboard_menu_tree(menuCode, permissionContext?, contextSets?)
| Parameter | Type | Description |
|---|
menuCode | string | Menu code (e.g. 'sidebar'). Resolved through MenuCodeResolverInterface before the DB lookup. |
permissionContext | mixed | Optional value passed to your MenuPermissionCheckerInterface. Defaults to the current Request. |
contextSets | array|null | Ordered 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)
isCurrent — true when this item’s route matches the current request
hasCurrentInBranch — true 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.
Returns the render configuration for a menu — CSS classes, icon settings, collapsible flags, and more.
dashboard_menu_config(menuCode, contextSets?)
| Parameter | Type | Description |
|---|
menuCode | string | Menu code (resolved the same way as in dashboard_menu_tree). |
contextSets | array|null | Ordered list of context objects. |
Return type: array with the following keys:
| Key | Type | Description |
|---|
classes | array<string, string> | CSS classes: menu, item, link, children, section_label, class_current, class_branch_expanded, class_has_children, class_expanded, class_collapsed. |
ul_id | string|null | HTML id attribute for the root <ul>. |
item_span_active | bool | When true, non-section items are wrapped in an extra <span>. |
item_span_class | string | CSS class(es) for the optional item wrapper <span>. |
icon_size | string | CSS size for icons (e.g. '1em', '16px'). |
depth_limit | int|null | Maximum depth to render. null = unlimited. |
icons | array{enabled: bool, use_ux_icons: bool, default: string|null} | Icon rendering options. |
collapsible | bool | Wrap the menu in a collapsible block with a toggle button. |
collapsible_expanded | bool | Whether the collapsible block starts open. |
nested_collapsible | bool | Give each item with children its own collapse toggle. |
menu_name | string|null | Human-readable name used as the collapsible toggle label. |
Generates the URL for a MenuItem.
dashboard_menu_href(item)
| Parameter | Type | Description |
|---|
item | MenuItem | The 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.
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
} %}
Generating a link URL manually
{% 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
} %}