You are here

menu--secondary-menu.html.twig in Drupal 10

Olivero's theme implementation for the menus in the secondary_menu region.

Available variables:

  • menu_name: The machine name of the menu.
  • items: A nested list of menu items. Each menu item contains:
    • attributes: HTML attributes for the menu item.
    • below: The menu item child items.
    • title: The menu link title.
    • url: The menu link url, instance of \Drupal\Core\Url
    • localized_options: Menu link localized options.
    • is_expanded: TRUE if the link has visible children within the current menu tree.
    • is_collapsed: TRUE if the link has children within the current menu tree that are not currently visible.
    • in_active_trail: TRUE if the link is in the active trail.

File

core/themes/olivero/templates/navigation/menu--secondary-menu.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Olivero's theme implementation for the menus in the secondary_menu region.
  5. *
  6. * Available variables:
  7. * - menu_name: The machine name of the menu.
  8. * - items: A nested list of menu items. Each menu item contains:
  9. * - attributes: HTML attributes for the menu item.
  10. * - below: The menu item child items.
  11. * - title: The menu link title.
  12. * - url: The menu link url, instance of \Drupal\Core\Url
  13. * - localized_options: Menu link localized options.
  14. * - is_expanded: TRUE if the link has visible children within the current
  15. * menu tree.
  16. * - is_collapsed: TRUE if the link has children within the current menu tree
  17. * that are not currently visible.
  18. * - in_active_trail: TRUE if the link is in the active trail.
  19. *
  20. * @ingroup themeable
  21. */
  22. #}
  23. {{ attach_library('olivero/navigation-secondary') }}
  24. {% import _self as menus %}
  25. {#
  26. We call a macro which calls itself to render the full tree.
  27. @see https://twig.symfony.com/doc/3.x/tags/macro.html
  28. #}
  29. {% set attributes = attributes.addClass('menu') %}
  30. {{ menus.menu_links(items, attributes, 0) }}
  31. {% macro menu_links(items, attributes, menu_level) %}
  32. {% set secondary_nav_level = 'secondary-nav__menu--level-' ~ (menu_level + 1) %}
  33. {% import _self as menus %}
  34. {% if items %}
  35. <ul{{ attributes.addClass('secondary-nav__menu', secondary_nav_level) }}>
  36. {% set attributes = attributes.removeClass(secondary_nav_level) %}
  37. {% for item in items %}
  38. {% if item.url.isRouted and item.url.routeName == '<nolink>' %}
  39. {% set menu_item_type = 'nolink' %}
  40. {% elseif item.url.isRouted and item.url.routeName == '<button>' %}
  41. {% set menu_item_type = 'button' %}
  42. {% else %}
  43. {% set menu_item_type = 'link' %}
  44. {% endif %}
  45. {% set item_classes = [
  46. 'secondary-nav__menu-item',
  47. 'secondary-nav__menu-item--' ~ menu_item_type,
  48. 'secondary-nav__menu-item--level-' ~ (menu_level + 1),
  49. item.in_active_trail ? 'secondary-nav__menu-item--active-trail',
  50. item.below ? 'secondary-nav__menu-item--has-children',
  51. ]
  52. %}
  53. {% set link_classes = [
  54. 'secondary-nav__menu-link',
  55. 'secondary-nav__menu-link--' ~ menu_item_type,
  56. 'secondary-nav__menu-link--level-' ~ (menu_level + 1),
  57. item.in_active_trail ? 'secondary-nav__menu-link--active-trail',
  58. item.below ? 'secondary-nav__menu-link--has-children',
  59. ]
  60. %}
  61. <li{{ item.attributes.addClass(item_classes) }}>
  62. {{ link(item.title, item.url, { 'class': link_classes }) }}
  63. {% if item.below %}
  64. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  65. {% endif %}
  66. </li>
  67. {% endfor %}
  68. </ul>
  69. {% endif %}
  70. {% endmacro %}

Related topics