oliverdavies.uk-drupal-old/web/themes/custom/opdavies/templates/menu/menu--main.html.twig

59 lines
2.2 KiB
Twig

{#
/**
* @file
* Theme override to display a menu.
*
* Available variables:
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
* - below: The menu item child items.
* - title: The menu link title.
* - url: The menu link url, instance of \Drupal\Core\Url
* - localized_options: Menu link localized options.
* - is_expanded: TRUE if the link has visible children within the current
* menu tree.
* - is_collapsed: TRUE if the link has children within the current menu tree
* that are not currently visible.
* - in_active_trail: TRUE if the link is in the active trail.
*/
#}
{% import _self as menus %}
{#
We call a macro which calls itself to render the full tree.
@see https://twig.symfony.com/doc/1.x/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}
{% macro menu_links(items, attributes, menu_level) %}
{% import _self as menus %}
{% if items %}
<div class="w-full md:block" :class="[ isOpen ? 'block' : 'hidden' ]">
{% if menu_level == 0 %}
<ul{{ attributes.addClass('
w-full h-full mt-2px py-4 bg-blue-700
md:mt-0 md:mx-0 md:relative md:flex md:flex-wrap md:flex-1 md:justify-end
md:bg-blue-700 md:border-b-0
') }}>
{% else %}
<ul>
{% endif %}
{% for item in items %}
<li{{ item.attributes.addClass('flex flex-1 justify-center') }}>
{% set linkClasses = ['w-full flex items-center mx-4 mt-1 -mb-px py-3 px-4 block rounded text-base text-white no-underline hover:underline focus:outline-none focus:underline md:py-1 md:px-2 md:mx-2 md:mt-0 md:mr-0'] %}
{% if item.in_active_trail %}
{% set linkClasses = linkClasses|merge(['cursor-default bg-blue-700 hover:border-blue-600 hover:no-underline md:bg-blue-700']) %}
{% endif %}
{{ link(item.title, item.url, { class: linkClasses|join(' ') }) }}
{% if item.below %}
{{ menus.menu_links(item.below, attributes, menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endmacro %}