You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

6 years ago
{#
/**
* @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 %}