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.html.twig' with {
  23. attributes: create_attribute({'aria-expanded': 'false', 'aria-controls': 'admin-toolbar', 'type': 'button'}),
  24. icon: 'burger',
  25. text: 'Expand sidebar'|t,
  26. extra_classes: 'admin-toolbar-control-bar__burger',
  27. } only %}
  28. </div>
  29. </div>
  30. <aside
  31. {{ attributes.addClass('admin-toolbar').setAttribute('id', 'admin-toolbar').setAttribute('data-drupal-admin-styles', true) }}
  32. >
  33. {# This lil' div will get the Drupal.displace() attributes added to it via JS. #}
  34. <div class="admin-toolbar__displace-placeholder"></div>
  35. <div class="admin-toolbar__scroll-wrapper">
  36. {% set title_menu = 'admin-toolbar-title'|clean_unique_id %}
  37. {# @todo - We should get rid of this ID below. #}
  38. <nav {{ region_attributes.content.setAttribute('id', 'menu-builder').addClass('admin-toolbar__content').setAttribute('aria-labelledby', title_menu) }}>
  39. <h3 id="{{ title_menu }}" class="visually-hidden">{{ 'Administrative toolbar content'|t }}</h3>
  40. {# @todo - Needs to be placed here so we can have the header footer on mobile. #}
  41. <div class="admin-toolbar__header">
  42. {% if not content.settings.hide_logo %}
  43. <a class="admin-toolbar__logo" href="{{ path('<front>') }}">
  44. {% if content.settings.logo_path is not null %}
  45. <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) }}">
  46. {% else %}
  47. {% include '@navigation/logo.svg.twig' with {
  48. label: 'Navigation logo'|t
  49. } only %}
  50. {% endif %}
  51. </a>
  52. {% endif %}
  53. {% include '@navigation/toolbar-button.html.twig' with {
  54. attributes: create_attribute({ 'data-toolbar-back-control': true, 'tabindex': '-1' }),
  55. extra_classes: 'admin-toolbar__back-button',
  56. icon: 'back',
  57. text: 'Back'|t,
  58. } only %}
  59. {% include '@navigation/toolbar-button.html.twig' with {
  60. attributes: create_attribute({ 'aria-controls': 'admin-toolbar', 'tabindex': '-1', 'type': 'button' }),
  61. extra_classes: 'admin-toolbar__close-button',
  62. icon: 'cross',
  63. label_classes: 'visually-hidden',
  64. text: 'Collapse sidebar'|t,
  65. } only %}
  66. </div>
  67. {{ content.content }}
  68. </nav>
  69. {% set title_menu_footer = 'admin-toolbar-footer'|clean_unique_id %}
  70. <nav {{ region_attributes.footer.setAttribute('id', 'menu-footer').addClass('admin-toolbar__footer').setAttribute('aria-labelledby', title_menu_footer) }}>
  71. <h3 id="{{ title_menu_footer }}" class="visually-hidden">{{ 'Administrative toolbar footer'|t }}</h3>
  72. {{ content.footer }}
  73. <button aria-controls="admin-toolbar" class="admin-toolbar__expand-button" type="button">
  74. <span class="visually-hidden" data-text>{{ 'Collapse sidebar'|t }}</span>
  75. </button>
  76. </nav>
  77. </div>
  78. </aside>
  79. <div class="admin-toolbar-overlay" aria-controls="admin-toolbar" data-drupal-admin-styles></div>
  80. <script>
  81. if (localStorage.getItem('Drupal.navigation.sidebarExpanded') !== 'false' && (window.matchMedia('(min-width: 1024px)').matches)) {
  82. document.documentElement.setAttribute('data-admin-toolbar', 'expanded');
  83. }
  84. </script>

Related topics


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