You are here

responsive-menu-off-canvas.html.twig in Responsive and off-canvas menu 4.4.x

Theme override to display a menu.

This is a clone of the 'stable' theme's menu.html.twig file and is used to ensure the correct markup is provided to mmenu (the off-canvas menu).

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

templates/responsive-menu-off-canvas.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a menu.
  5. *
  6. * This is a clone of the 'stable' theme's menu.html.twig file and is used to
  7. * ensure the correct markup is provided to mmenu (the off-canvas menu).
  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/1.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 }}>
  35. {% else %}
  36. <ul>
  37. {% endif %}
  38. {% for item in items %}
  39. <li{{ item.attributes }}>
  40. {{ link(item.title, item.url) }}
  41. {% if item.below %}
  42. {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  43. {% endif %}
  44. </li>
  45. {% endfor %}
  46. </ul>
  47. {% endif %}
  48. {% endmacro %}