file menu--navbar.html.twig

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

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in