You are here

menu.html.twig in Open Social 8.7

Theme override to display a 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

themes/socialbase/templates/navigation/menu.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a menu.
  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. #}
  21. <div class="navbar {{'menu-' ~ menu_name|clean_class}}">
  22. {% import _self as menus %}
  23. {#
  24. We call a macro which calls itself to render the full tree.
  25. @see http://twig.sensiolabs.org/doc/tags/macro.html
  26. #}
  27. {{ menus.menu_links(items, attributes, 0, menu_name|clean_class) }}
  28. {% macro menu_links(items, attributes, menu_level, menu_name) %}
  29. {% import _self as menus %}
  30. {% if items %}
  31. {% if menu_level == 0 %}
  32. <ul role="navigation"{{ attributes.addClass('nav', 'navbar-nav', menu_name) }}>
  33. {% else %}
  34. <ul{{ attributes.addClass('dropdown-menu', menu_name) }}>
  35. {% endif %}
  36. {% for item in items %}
  37. {%
  38. set item_classes = [
  39. 'expanded',
  40. 'dropdown',
  41. item.in_active_trail ? 'active',
  42. ]
  43. %}
  44. {% if menu_level == 0 and item.is_expanded %}
  45. <li{{ item.attributes.addClass(item_classes) }}>
  46. <a href="{{ item.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
  47. {% else %}
  48. <li>
  49. {{ link(item.title, item.url) }}
  50. {% endif %}
  51. {% if item.below %}
  52. {{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1, menu_name) }}
  53. {% endif %}
  54. </li>
  55. {% endfor %}
  56. </ul>
  57. {% endif %}
  58. {% endmacro %}
  59. </div>