This repository was archived by the owner on Dec 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdruki-content-toc.html.twig
More file actions
47 lines (46 loc) · 1.49 KB
/
druki-content-toc.html.twig
File metadata and controls
47 lines (46 loc) · 1.49 KB
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
43
44
45
46
47
{#
/**
* @file
* Default theme implementation to present content TOC.
*
* Available variables:
* - links: The array with link for TOC.
*
* @see template_preprocess_druki_content_toc().
*/
#}
{% import _self as toc %}
{% set bem_block = 'druki-content-toc' %}
<div{{ attributes.addClass(bem_block) }}>
{% set bem_base = bem_block ~ '__' %}
{% do attributes.removeClass(bem_block) %}
{{ toc.links(links, attributes, 0, bem_base) }}
</div>
{% macro links(links, attributes, toc_level, bem_base) %}
{% import _self as toc %}
{% if links %}
{% if toc_level == 0 %}
<ul{{ attributes.addClass([bem_base ? bem_base ~ 'menu']) }}>
{% for item in links %}
<li class="{{ bem_base ~ 'item' }}">
<a href="#{{ item.anchor }}" class="{{ bem_base ~ 'link' }}">{{ item.text }}</a>
{% if item.children %}
{{ toc.links(item.children, attributes, item.level, bem_base) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<ul class="{% if bem_base %}{{ bem_base }}submenu{% endif %}">
{% for item in links %}
<li class="{{ bem_base ~ 'item' }}">
<a href="#{{ item.anchor }}" class="{{ bem_base ~ 'link' }}" title="{{ item.text }}">{{ item.text }}</a>
{% if item.children %}
{{ toc.links(item.children, attributes, item.level + 1, bem_base) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
{% endmacro %}