Same filename in this branch
  1. 10 core/modules/book/templates/book-tree.html.twig
  2. 10 core/themes/olivero/templates/navigation/book-tree.html.twig
  3. 10 core/themes/stable9/templates/navigation/book-tree.html.twig
  4. 10 core/themes/claro/templates/classy/navigation/book-tree.html.twig
  5. 10 core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
Same filename and directory in other branches
  1. 9 core/themes/olivero/templates/navigation/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/themes/olivero/templates/navigation/book-tree.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override to display a book tree.
  5. *
  6. * Returns HTML for a wrapper for a book sub-tree.
  7. *
  8. * Available variables:
  9. * - items: A nested list of book items. Each book item contains:
  10. * - attributes: HTML attributes for the book item.
  11. * - below: The book item child items.
  12. * - title: The book link title.
  13. * - url: The book link URL, instance of \Drupal\Core\Url.
  14. * - is_expanded: TRUE if the link has visible children within the current
  15. * book tree.
  16. * - is_collapsed: TRUE if the link has children within the current book tree
  17. * that are not currently visible.
  18. * - in_active_trail: TRUE if the link is in the active trail.
  19. */
  20. #}
  21. {% import _self as book_tree %}
  22. {#
  23. We call a macro which calls itself to render the full tree.
  24. @see https://twig.symfony.com/doc/3.x/tags/macro.html
  25. #}
  26. {{ book_tree.book_links(items, attributes, 0) }}
  27. {% macro book_links(items, attributes, menu_level) %}
  28. {% import _self as book_tree %}
  29. {% if items %}
  30. {% if menu_level == 0 %}
  31. <ul{{ attributes.addClass('book-navigation__menu menu', 'menu--level-' ~ (menu_level + 1)) }}>
  32. {% else %}
  33. <ul class='menu menu--level-{{ menu_level + 1 }}'>
  34. {% endif %}
  35. {% for item in items %}
  36. {%
  37. set item_classes = [
  38. 'book-navigation__item',
  39. 'menu__item--level-' ~ (menu_level + 1),
  40. item.is_expanded ? 'menu__item--expanded',
  41. item.is_collapsed ? 'menu__item--collapsed',
  42. item.in_active_trail ? 'menu__item--active-trail',
  43. ]
  44. %}
  45. {% set link_classes = [
  46. 'book-navigation__link',
  47. 'menu__link',
  48. 'menu__link--link',
  49. 'menu__link--level-' ~ (menu_level + 1),
  50. item.in_active_trail ? 'menu__link--active-trail',
  51. item.below ? 'menu__link--has-children',
  52. ]
  53. %}
  54. <li{{ item.attributes.addClass(item_classes) }}>
  55. {{ link(item.title, item.url, {
  56. 'class': link_classes
  57. })
  58. }}
  59. {% if item.below %}
  60. {{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
  61. {% endif %}
  62. </li>
  63. {% endfor %}
  64. </ul>
  65. {% endif %}
  66. {% endmacro %}