file menu--offcanvas.html.twig

Theme override to display an offcanvas 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--offcanvas.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display an offcanvas 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__offcanvas()
  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-nav',
  37. menu_level == 0 ? 'uk-nav-default',
  38. menu_level == 0 ? 'uk-nav-parent-icon',
  39. menu_level > 0 ? 'uk-nav-sub',
  40. ]
  41. %}
  42. <ul{{ attributes.addClass(classes) }}{% if menu_level == 0 %} uk-nav{% endif %}>
  43. {% for item in items %}
  44. {% set item_classes = [item.below ? 'uk-parent'] %}
  45. {% if item.display_item %}
  46. <li{{ item.attributes.addClass(item_classes) }}>
  47. {% if item.has_url %}
  48. {{ link(item.title, item.url) }}
  49. {% else %}
  50. <a href="#">{{ item.title }}</a>
  51. {% endif %}
  52. {% if item.below %}
  53. {{ menus.menu_links(item.below, attributes.removeClass(classes), menu_level + 1) }}
  54. {% endif %}
  55. {% endif %}
  56. </li>
  57. {% endfor %}
  58. </ul>
  59. {% endif %}
  60. {% 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