book-tree.html.twig
Same filename in this branch
- 8.9.x core/themes/seven/templates/classy/navigation/book-tree.html.twig
- 8.9.x core/themes/claro/templates/classy/navigation/book-tree.html.twig
- 8.9.x core/themes/bartik/templates/classy/navigation/book-tree.html.twig
- 8.9.x core/themes/stable/templates/navigation/book-tree.html.twig
- 8.9.x core/themes/classy/templates/navigation/book-tree.html.twig
- 8.9.x core/modules/book/templates/book-tree.html.twig
Same filename in other branches
- 9 core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
- 9 core/themes/olivero/templates/navigation/book-tree.html.twig
- 9 core/themes/stable9/templates/navigation/book-tree.html.twig
- 9 core/themes/seven/templates/classy/navigation/book-tree.html.twig
- 9 core/themes/claro/templates/classy/navigation/book-tree.html.twig
- 9 core/themes/bartik/templates/classy/navigation/book-tree.html.twig
- 9 core/themes/stable/templates/navigation/book-tree.html.twig
- 9 core/themes/classy/templates/navigation/book-tree.html.twig
- 9 core/modules/book/templates/book-tree.html.twig
- 10 core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
- 10 core/themes/olivero/templates/navigation/book-tree.html.twig
- 10 core/themes/stable9/templates/navigation/book-tree.html.twig
- 10 core/themes/claro/templates/classy/navigation/book-tree.html.twig
- 10 core/modules/book/templates/book-tree.html.twig
- 11.x core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
- 11.x core/themes/olivero/templates/navigation/book-tree.html.twig
- 11.x core/themes/stable9/templates/navigation/book-tree.html.twig
- 11.x core/themes/claro/templates/classy/navigation/book-tree.html.twig
- 11.x core/modules/book/templates/book-tree.html.twig
Theme override to display a book tree.
Returns HTML for a wrapper for a book sub-tree.
Available variables:
- items: A nested list of book items. Each book item contains:
- attributes: HTML attributes for the book item.
- below: The book item child items.
- title: The book link title.
- url: The book link URL, instance of \Drupal\Core\Url.
- is_expanded: TRUE if the link has visible children within the current book tree.
- is_collapsed: TRUE if the link has children within the current book tree that are not currently visible.
- in_active_trail: TRUE if the link is in the active trail.
File
-
core/
profiles/ demo_umami/ themes/ umami/ templates/ classy/ navigation/ book-tree.html.twig
View source
- {#
- /**
- * @file
- * Theme override to display a book tree.
- *
- * Returns HTML for a wrapper for a book sub-tree.
- *
- * Available variables:
- * - items: A nested list of book items. Each book item contains:
- * - attributes: HTML attributes for the book item.
- * - below: The book item child items.
- * - title: The book link title.
- * - url: The book link URL, instance of \Drupal\Core\Url.
- * - is_expanded: TRUE if the link has visible children within the current
- * book tree.
- * - is_collapsed: TRUE if the link has children within the current book tree
- * that are not currently visible.
- * - in_active_trail: TRUE if the link is in the active trail.
- */
- #}
- {% import _self as book_tree %}
-
- {#
- We call a macro which calls itself to render the full tree.
- @see https://twig.symfony.com/doc/1.x/tags/macro.html
- #}
- {{ book_tree.book_links(items, attributes, 0) }}
-
- {% macro book_links(items, attributes, menu_level) %}
- {% import _self as book_tree %}
- {% if items %}
- {% if menu_level == 0 %}
- <ul{{ attributes.addClass('menu') }}>
- {% else %}
- <ul class="menu">
- {% endif %}
- {% for item in items %}
- {%
- set classes = [
- 'menu-item',
- item.is_expanded ? 'menu-item--expanded',
- item.is_collapsed ? 'menu-item--collapsed',
- item.in_active_trail ? 'menu-item--active-trail',
- ]
- %}
- <li{{ item.attributes.addClass(classes) }}>
- {{ link(item.title, item.url) }}
- {% if item.below %}
- {{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
- {% endif %}
- </li>
- {% endfor %}
- </ul>
- {% endif %}
- {% endmacro %}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.