Files
myep/templates/admin/_partials/_sidebar_menu.html.twig
T

64 lines
2.6 KiB
Twig

{#
KnpMenu template for the sidebar (layout_sidebar.html.twig). Items of the first level:
- a link (`.sidebar-link`); with children, they show below it while it or a child is current
- without a URI but with children: a group that opens in place (<details>), open while a child is current
- extras `heading` (a group heading) or `divider` (a line)
- extras `icon`: rendered with _partials/_icon.html.twig (`icon`, `class`), as myep's icon() does
#}
{% extends 'knp_menu.html.twig' %}
{% block list %}
{% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
{% if item.level == 0 %}
<ul class="space-y-1">
{{ block('children') }}
</ul>
{% elseif item.uri is empty or matcher.isCurrent(item) or matcher.isAncestor(item) %}
<ul class="mt-1 space-y-1">
{{ block('children') }}
</ul>
{% endif %}
{% endif %}
{% endblock %}
{% block item %}
{% if item.displayed and item.extras.heading is defined %}
<li class="sidebar-heading">{{ item.label }}</li>
{% elseif item.displayed and item.extras.divider is defined %}
<li><hr class="my-4 border-line"></li>
{% elseif item.displayed %}
<li>
{% if item.uri is empty and item.hasChildren and item.displayChildren %}
<details class="sidebar-group" {{ matcher.isAncestor(item) ? 'open' }}>
<summary class="sidebar-link {{ matcher.isAncestor(item) ? 'text-brand' }}">{{ block('label') }}</summary>
{{ block('list') }}
</details>
{% else %}
{{ block('linkElement') }}
{{ block('list') }}
{% endif %}
</li>
{% endif %}
{% endblock %}
{% block linkElement %}
{% import _self as knp_menu %}
{% set is_current = matcher.isCurrent(item) %}
<a href="{{ item.uri }}"
class="{{ item.level == 1 ? 'sidebar-link' : 'sidebar-sublink' }} {{ not is_current and item.level == 1 and matcher.isAncestor(item) ? 'sidebar-link--ancestor' }}"
{% if is_current %}aria-current="page"{% endif %}
{{ knp_menu.attributes(item.linkAttributes) }}>{{ block('label') }}</a>
{% endblock %}
{% block label -%}
{% if item.extras.icon is defined -%}
{{ include('_partials/_icon.html.twig', {
icon: item.extras.icon,
class: 'size-5 shrink-0 ' ~ (matcher.isCurrent(item) or matcher.isAncestor(item) ? 'text-brand' : 'text-muted'),
}) }}
<span class="flex-1">{{ item.label }}</span>
{%- else -%}
{{ item.label }}
{%- endif %}
{%- endblock %}