grav-theme-future2021/templates/macros/macros.html.twig
2023-10-28 22:14:49 +02:00

49 lines
No EOL
1.4 KiB
Twig

{# MACRO FOR PAGE-TOC PLUGIN SUPPORT #}
{% macro toc_loop(items) %}
{% import _self as toc_macros %}
{% 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>
{{ toc_macros.toc_loop(item.children) }}
</ul>
{% endif %}
</li>
{% endfor %}
{% endmacro %}
{# MACRO FOR TOP MENU NAVIGATION #}
{% macro nav_loop(page) %}
{% import _self as nav_macros %}
{% for p in page.children.visible %}
{% set current_page = (p.active or p.activeChild) ? 'active' : '' %}
{% if p.children.visible.count > 0 %}
<li class="{{ current_page }}">
<a>
{% if p.header.icon %}
<i class="fa fa-{{ p.header.icon }}"></i>
{% endif %}
{{ p.menu }}
{% if p.routable ?? false %}&nbsp;<i class="fa fa-angle-down"></i>
{% endif %}
</a>
<ul>
{{ nav_macros.nav_loop(p) }}
</ul>
</li>
{% else %}
<li class="{{ current_page }}">
<a href="{{ p.url }}">
{% if p.header.icon %}
<i class="fa fa-{{ p.header.icon }}"></i>
{% endif %}
<span>{{ p.menu }}</span>
</a>
</li>
{% endif %}
{% endfor %}
{% endmacro %}