navigation.html.twig

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

Related topics


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