navigation.html.twig

Same filename and directory in other branches
  1. 11.x core/modules/navigation/layouts/navigation.html.twig

Default theme implementation to display a navigation layout.

Available variables:

  • content: The content for this layout.
  • attributes: HTML attributes for the layout <div>.
  • hide_logo: Whether to hide the logo.
  • logo_path: The path to the logo image if logo_managed in navigation.settings configuration has been set.
  • logo_width: The width of the logo image. Available if logo_path points to a valid image file.
  • logo_height: The height of the logo image. Available if logo_path points to a valid image file.

File

core/modules/navigation/layouts/navigation.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a navigation layout.
  5. *
  6. * Available variables:
  7. * - content: The content for this layout.
  8. * - attributes: HTML attributes for the layout <div>.
  9. * - hide_logo: Whether to hide the logo.
  10. * - logo_path: The path to the logo image if logo_managed in
  11. * navigation.settings configuration has been set.
  12. * - logo_width: The width of the logo image. Available if
  13. * logo_path points to a valid image file.
  14. * - logo_height: The height of the logo image. Available if
  15. * logo_path points to a valid image file.
  16. *
  17. * @ingroup themeable
  18. */
  19. #}
  20. {% set control_bar_attributes = create_attribute() %}
  21. <div {{ control_bar_attributes.addClass('admin-toolbar-control-bar').setAttribute('data-drupal-admin-styles', '').setAttribute('data-offset-top', '') }}>
  22. <div class="admin-toolbar-control-bar__content">
  23. {% include '@navigation/toolbar-button.html.twig' with {
  24. attributes: create_attribute({'aria-expanded': 'false', 'aria-controls': 'admin-toolbar', 'type': 'button'}),
  25. icon: 'burger',
  26. text: 'Expand sidebar'|t,
  27. extra_classes: 'admin-toolbar-control-bar__burger',
  28. } only %}
  29. </div>
  30. </div>
  31. <aside
  32. {{ attributes.addClass('admin-toolbar').setAttribute('id', 'admin-toolbar').setAttribute('data-drupal-admin-styles', true) }}
  33. >
  34. {# This lil' div will get the Drupal.displace() attributes added to it via JS. #}
  35. <div class="admin-toolbar__displace-placeholder"></div>
  36. <div class="admin-toolbar__scroll-wrapper">
  37. {% set title_menu = 'admin-toolbar-title'|clean_unique_id %}
  38. {# @todo - We should get rid of this ID below. #}
  39. <nav {{ region_attributes.content.setAttribute('id', 'menu-builder').addClass('admin-toolbar__content').setAttribute('aria-labelledby', title_menu) }}>
  40. <h3 id="{{ title_menu }}" class="visually-hidden">{{ 'Administrative toolbar content'|t }}</h3>
  41. {# @todo - Needs to be placed here so we can have the header footer on mobile. #}
  42. <div class="admin-toolbar__header">
  43. {% if not hide_logo %}
  44. <a class="admin-toolbar__logo" href="{{ path('<front>') }}">
  45. {% if logo_path %}
  46. <img alt="{{ 'Navigation logo'|t }}" src="{{ file_url(logo_path) }}" loading="eager" width="{{ logo_width|default(40) }}" height="{{ logo_height|default(40) }}">
  47. {% else %}
  48. {% include '@navigation/logo.svg.twig' with {
  49. label: 'Navigation logo'|t
  50. } only %}
  51. {% endif %}
  52. </a>
  53. {% endif %}
  54. {% include '@navigation/toolbar-button.html.twig' with {
  55. attributes: create_attribute({ 'data-toolbar-back-control': true, 'tabindex': '-1' }),
  56. extra_classes: 'admin-toolbar__back-button',
  57. icon: 'back',
  58. text: 'Back'|t,
  59. } only %}
  60. {% include '@navigation/toolbar-button.html.twig' with {
  61. attributes: create_attribute({ 'aria-controls': 'admin-toolbar', 'tabindex': '-1', 'type': 'button' }),
  62. extra_classes: 'admin-toolbar__close-button',
  63. icon: 'cross',
  64. label_classes: 'visually-hidden',
  65. text: 'Collapse sidebar'|t,
  66. } only %}
  67. </div>
  68. {{ content.content }}
  69. </nav>
  70. {% set title_menu_footer = 'admin-toolbar-footer'|clean_unique_id %}
  71. <nav {{ region_attributes.footer.setAttribute('id', 'menu-footer').addClass('admin-toolbar__footer').setAttribute('aria-labelledby', title_menu_footer) }}>
  72. <h3 id="{{ title_menu_footer }}" class="visually-hidden">{{ 'Administrative toolbar footer'|t }}</h3>
  73. {{ content.footer }}
  74. <button aria-controls="admin-toolbar" class="admin-toolbar__expand-button" type="button">
  75. <span class="visually-hidden" data-text>{{ 'Collapse sidebar'|t }}</span>
  76. </button>
  77. </nav>
  78. </div>
  79. </aside>
  80. <div class="admin-toolbar-overlay" aria-controls="admin-toolbar" data-drupal-admin-styles></div>
  81. <script>
  82. if (localStorage.getItem('Drupal.navigation.sidebarExpanded') !== 'false' && (window.matchMedia('(min-width: 1024px)').matches)) {
  83. document.documentElement.setAttribute('data-admin-toolbar', 'expanded');
  84. }
  85. </script>

Related topics


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