wiki-grav/plugins/page-toc/templates/components/page-toc.html.twig
2022-06-06 18:16:01 +02:00

26 lines
846 B
Twig

{% macro toc_loop(items) %}
{% import _self as self %}
{% for item in items %}
{% set class = loop.first ? 'first' : loop.last ? 'last' : null %}
<li {% if class %}class="{{ class }}"{% endif %}>
<a href="{{ item.uri }}">{{ item.label }}</a>
{% if item.children|length > 0 %}
<ul>
{{ _self.toc_loop(item.children) }}
</ul>
{% endif %}
</li>
{% endfor %}
{% endmacro %}
{% if active or toc_config_var('active') %}
<div class="page-toc">
{% set table_of_contents = toc_items(page.content) %}
{% if table_of_contents is not empty %}
<h4>{{ 'PLUGIN_PAGE_TOC.TABLE_OF_CONTENTS'|t }}</h4>
<ul>
{{ _self.toc_loop(table_of_contents.children) }}
</ul>
{% endif %}
</div>
{% endif %}