book-tree.html.twig

Same filename in this branch
  1. 10 core/profiles/demo_umami/themes/umami/templates/classy/navigation/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
Same filename in other branches
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
  2. 9 core/themes/olivero/templates/navigation/book-tree.html.twig
  3. 9 core/themes/stable9/templates/navigation/book-tree.html.twig
  4. 9 core/themes/seven/templates/classy/navigation/book-tree.html.twig
  5. 9 core/themes/claro/templates/classy/navigation/book-tree.html.twig
  6. 9 core/themes/bartik/templates/classy/navigation/book-tree.html.twig
  7. 9 core/themes/stable/templates/navigation/book-tree.html.twig
  8. 9 core/themes/classy/templates/navigation/book-tree.html.twig
  9. 9 core/modules/book/templates/book-tree.html.twig
  10. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
  11. 8.9.x core/themes/seven/templates/classy/navigation/book-tree.html.twig
  12. 8.9.x core/themes/claro/templates/classy/navigation/book-tree.html.twig
  13. 8.9.x core/themes/bartik/templates/classy/navigation/book-tree.html.twig
  14. 8.9.x core/themes/stable/templates/navigation/book-tree.html.twig
  15. 8.9.x core/themes/classy/templates/navigation/book-tree.html.twig
  16. 8.9.x core/modules/book/templates/book-tree.html.twig
  17. 11.x core/profiles/demo_umami/themes/umami/templates/classy/navigation/book-tree.html.twig
  18. 11.x core/themes/olivero/templates/navigation/book-tree.html.twig
  19. 11.x core/themes/stable9/templates/navigation/book-tree.html.twig
  20. 11.x core/themes/claro/templates/classy/navigation/book-tree.html.twig
  21. 11.x core/modules/book/templates/book-tree.html.twig

Default theme implementation 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/modules/book/templates/book-tree.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation 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. * @ingroup themeable
  21. */
  22. #}
  23. {% import _self as book_tree %}
  24. {#
  25. We call a macro which calls itself to render the full tree.
  26. @see https://twig.symfony.com/doc/3.x/tags/macro.html
  27. #}
  28. {{ book_tree.book_links(items, attributes, 0) }}
  29. {% macro book_links(items, attributes, menu_level) %}
  30. {% import _self as book_tree %}
  31. {% if items %}
  32. {% if menu_level == 0 %}
  33. <ul{{ attributes }}>
  34. {% else %}
  35. <ul>
  36. {% endif %}
  37. {% for item in items %}
  38. <li{{ item.attributes }}>
  39. {{ link(item.title, item.url) }}
  40. {% if item.below %}
  41. {{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
  42. {% endif %}
  43. </li>
  44. {% endfor %}
  45. </ul>
  46. {% endif %}
  47. {% endmacro %}

Related topics


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