menu--toolbar.html.twig

Same filename in this branch
  1. 11.x core/themes/stable9/templates/navigation/menu--toolbar.html.twig
  2. 11.x core/modules/toolbar/templates/menu--toolbar.html.twig
Same filename in other branches
  1. 9 core/themes/stable9/templates/navigation/menu--toolbar.html.twig
  2. 9 core/themes/claro/templates/navigation/menu--toolbar.html.twig
  3. 9 core/themes/stable/templates/navigation/menu--toolbar.html.twig
  4. 9 core/modules/toolbar/templates/menu--toolbar.html.twig
  5. 8.9.x core/themes/stable/templates/navigation/menu--toolbar.html.twig
  6. 8.9.x core/modules/toolbar/templates/menu--toolbar.html.twig
  7. 10 core/themes/stable9/templates/navigation/menu--toolbar.html.twig
  8. 10 core/themes/claro/templates/navigation/menu--toolbar.html.twig
  9. 10 core/modules/toolbar/templates/menu--toolbar.html.twig

Theme override to display a toolbar menu.

If Claro is the admin theme, this template will be used by the active theme even if the active theme is not Claro.

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/claro/templates/navigation/menu--toolbar.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a toolbar menu.
  5. *
  6. * If Claro is the admin theme, this template will be used by the active theme
  7. * even if the active theme is not Claro.
  8. *
  9. * Available variables:
  10. * - menu_name: The machine name of the menu.
  11. * - items: A nested list of menu items. Each menu item contains:
  12. * - attributes: HTML attributes for the menu item.
  13. * - below: The menu item child items.
  14. * - title: The menu link title.
  15. * - url: The menu link URL, instance of \Drupal\Core\Url
  16. * - localized_options: Menu link localized options.
  17. * - is_expanded: TRUE if the link has visible children within the current
  18. * menu tree.
  19. * - is_collapsed: TRUE if the link has children within the current menu tree
  20. * that are not currently visible.
  21. * - in_active_trail: TRUE if the link is in the active trail.
  22. */
  23. #}
  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. {{ menus.menu_links(items, attributes, 0) }}
  30. {% macro menu_links(items, attributes, menu_level) %}
  31. {% import _self as menus %}
  32. {% if items %}
  33. {% if menu_level == 0 %}
  34. <ul{{ attributes.addClass('toolbar-menu', 'claro-toolbar-menu') }}>
  35. {% else %}
  36. <ul class="toolbar-menu">
  37. {% endif %}
  38. {% for item in items %}
  39. {%
  40. set classes = [
  41. 'menu-item',
  42. item.is_expanded ? 'menu-item--expanded',
  43. item.is_collapsed ? 'menu-item--collapsed',
  44. item.in_active_trail ? 'menu-item--active-trail',
  45. ]
  46. %}
  47. <li{{ item.attributes.addClass(classes) }}>
  48. {{ link(item.title, item.url) }}
  49. {% if item.below %}
  50. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  51. {% endif %}
  52. </li>
  53. {% endfor %}
  54. </ul>
  55. {% endif %}
  56. {% endmacro %}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.