summaryrefslogtreecommitdiffstats
path: root/core/themes/classy/templates/navigation/book-tree.html.twig
blob: 543696c924ae48efd0b89abd1de2b966b499c1a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{#
/**
 * @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.
 */
#}
{% import _self as book_tree %}

{#
  We call a macro which calls itself to render the full tree.
  @see http://twig.sensiolabs.org/doc/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 %}
        <li{{ item.attributes }}>
          {{ link(item.title, item.url) }}
          {% if item.below %}
            {{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
          {% endif %}
        </li>
      {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}