You are here

book-tree.html.twig in Open Social 8.9

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

themes/socialbase/templates/node/book/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 http://twig.sensiolabs.org/doc/tags/macro.html
  27. #}
  28. <div class="card__block">
  29. {{ book_tree.book_links(items, attributes, 0) }}
  30. </div>
  31. {% macro book_links(items, attributes, menu_level) %}
  32. {% import _self as book_tree %}
  33. {% if items %}
  34. {% if menu_level == 0 %}
  35. <ul{{ attributes.addClass('nav-book') }}>
  36. {% else %}
  37. <ul class="menu">
  38. {% endif %}
  39. {% for item in items %}
  40. {%
  41. set classes = [
  42. 'menu-item',
  43. item.below ? 'menu-item--has-children',
  44. item.is_expanded ? 'menu-item--expanded',
  45. item.is_collapsed ? 'menu-item--collapsed',
  46. item.in_active_trail ? 'menu-item--active-trail',
  47. ]
  48. %}
  49. <li{{ item.attributes.addClass(classes) }}>
  50. {{ link(item.title, item.url) }}
  51. {% if item.below %}
  52. {{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
  53. {% endif %}
  54. </li>
  55. {% endfor %}
  56. </ul>
  57. {% endif %}
  58. {% endmacro %}