toc-tree.html.twig in TOC API 8
Default theme implementation to display a Table of contents as a tree.
Returns HTML for a nested list representation of a Table of contents..
Available variables:
- tree: A nested list of header items. Each header item contains:
- list_tag: HTML tag for the list.
- list_attributes: HTML attributes for the list.
- attributes: HTML attributes for the table of contents or list item.
- below: The table of contents child items.
- title: The table of contents or header title.
- url: The header fragrment (ie hash) URL, instance of \Drupal\Core\Url.
2 theme calls to toc-tree.html.twig
- template_preprocess_toc_default in ./
toc_api.module - Prepares variables for a default table of contents.
- template_preprocess_toc_responsive in ./
toc_api.module - Prepares variables for a responsive table of contents.
File
templates/toc-tree.html.twigView source
- {#
- /**
- * @file
- * Default theme implementation to display a Table of contents as a tree.
- *
- * Returns HTML for a nested list representation of a Table of contents..
- *
- * Available variables:
- * - tree: A nested list of header items. Each header item contains:
- * - list_tag: HTML tag for the list.
- * - list_attributes: HTML attributes for the list.
- * - attributes: HTML attributes for the table of contents or list item.
- * - below: The table of contents child items.
- * - title: The table of contents or header title.
- * - url: The header fragrment (ie hash) URL, instance of \Drupal\Core\Url.
- *
- * @ingroup themeable
- */
- #}
- {#
- We call a macro which calls itself to render the full tree.
- @see http://twig.sensiolabs.org/doc/tags/macro.html
- #}
- {% import _self as toc_api_tree %}
- {% set classes = ['toc', 'toc-tree'] %}
-
- <div{{ attributes.addClass(classes) }}>
-
- {% if tree.title and not options.block %}
- <h3>{{ tree.title }}</h3>
- {% endif %}
-
- {{ toc_api_tree.tree_links(tree) }}
-
- </div>
-
- {% macro tree_links(item) %}
- {% import _self as toc_api_tree %}
-
- {% if item.below_type %}
- <ol class="{{ item.below_type }}">
- {% else %}
- <ul>
- {% endif %}
-
- {% for child_item in item.below %}
- <li{{ child_item.attributes.setAttribute('value', child_item.value) }}>
- {{ link(child_item.html, child_item.url) }}
- {% if child_item.below %}
- {{ toc_api_tree.tree_links(child_item) }}
- {% endif %}
- </li>
- {% endfor %}
-
- {% if item.below_type %}
- </ol>
- {% else %}
- </ul>
- {% endif %}
- {% endmacro %}