Skip to main content

dashboard_menu_icon_name

Resolves a full icon identifier to the short form expected by the icon library, using icon_library_prefix_map from the bundle configuration.
{{ iconString | dashboard_menu_icon_name }}
Input: A full icon identifier string, e.g. bootstrap-icons:house. Output: The resolved short form, e.g. bi:house, based on the icon_library_prefix_map configuration. If the prefix is not found in the map, the input is returned unchanged.
This filter is what the built-in menu.html.twig template uses internally before passing icon names to ux_icon(). You only need it directly when building a custom menu template.

How it works

The icon_library_prefix_map config maps verbose prefixes to the short aliases your icon library expects:
nowo_dashboard_menu.yaml
nowo_dashboard_menu:
  icon_library_prefix_map:
    'bootstrap-icons': 'bi'
    'heroicons': 'heroicons'
Given that configuration:
InputOutput
bootstrap-icons:housebi:house
bootstrap-icons:bar-chartbi:bar-chart
heroicons:homeheroicons:home
unknown-lib:starunknown-lib:star (unchanged)

Usage

{# In a custom menu template #}
{% for node in menuTree %}
  {% set item = node.item %}
  {% if menuConfig.icons.enabled and item.icon %}
    {% if menuConfig.icons.use_ux_icons %}
      {{ ux_icon(item.icon | dashboard_menu_icon_name, { height: menuConfig.icon_size }) }}
    {% else %}
      <i class="{{ item.icon | dashboard_menu_icon_name }}"></i>
    {% endif %}
  {% endif %}
  <span>{{ item.label }}</span>
{% endfor %}
{# Direct output example #}
{{ 'bootstrap-icons:house' | dashboard_menu_icon_name }}
{# Outputs: bi:house  (with bootstrap-icons: bi in icon_library_prefix_map) #}
The filter is applied automatically by the built-in template. You only need to call it manually in a custom override of menu.html.twig.