SU-SWS/stanford_profile_helper

View on GitHub
modules/jumpstart_ui/dist/templates/decanter/components/main-nav/main-nav.twig

Summary

Maintainability
Test Coverage
{#
+/**
+ * @file
+ * Main Navigation Component
+ *
+ * A navigation menu for the website.
+ *
+ * Available variables:
+ * - attributes: For additional HTML attributes not already provided.
+ * - modifier_class: Additional css classes to change look and behaviour of the component.
+ * - toggle_modifier_class: Additional css classes to change look and behaviour of the toggle.
+ * - aria_label: Aria label for the <nav> element. Default is "main menu". If there are multiple instances of the component on the same page, use a different aria_label for each instance.
+ * - list_items: Structured data that is iterable or custom markup
+ *
+ */
+#}
{#
  Template Include Paths
  Override these if you want to include a different template.
#}
{%- if template_path_search is empty -%}
  {%- set template_path_search = "@decanter/components/site-search/site-search.twig" -%}
{%- endif -%}

<nav {{ attributes }} class="su-main-nav no-js {{ modifier_class }}" aria-label="{{ aria_label|default('main menu') }}">
  <button class="su-main-nav__toggle {{ toggle_modifier_class }}" aria-expanded="false">{{ toggle_text|default('Menu') }}</button>
  <ul class="su-main-nav__menu-lv1">
      {% if list_items is iterable %}
        {# If no custom markup, generate markup based on structured data #}
        {% for item in list_items %}
          {% set is_parent = item.lv2 is empty ? false : true %}
          <li class="{% if is_parent %}su-main-nav__item--parent{% endif %} {% if item.current %}su-main-nav__item--current{% endif %}">
            {%- set the_attrs = "" %}
            {%- if item.attributes is not empty and item.attributes is iterable %}
              {%- for pair in item.attributes %}
                {% set the_attrs = the_attrs ~ ' ' ~ pair.attr ~ '="' ~ pair.value ~ '"' %}
              {% endfor -%}
            {% endif -%}
            <a href="{{ item.href }}" {{ the_attrs }} {% if is_parent %}aria-expanded="false"{% endif %}>{{ item.text }}</a>
            {%- if is_parent -%}
              <ul class="su-main-nav__menu-lv2">
                {%- for item_lv2 in item.lv2 -%}
                  <li class="{% if item_lv2.current %}su-main-nav__item--current{% endif %}">
                    {%- set the_attrs = "" %}
                    {%- if item_lv2.attributes is not empty and item_lv2.attributes is iterable %}
                      {%- for pair in item_lv2.attributes %}
                        {% set the_attrs = the_attrs ~ ' ' ~ pair.attr ~ '="' ~ pair.value ~ '"' %}
                      {% endfor -%}
                    {% endif -%}
                    <a href="{{ item_lv2.href }}" {{ the_attrs }}>{{ item_lv2.text }}</a>
                  </li>
                {% endfor %}
              </ul>
            {% endif -%}
          </li>
        {% endfor %}
      {% else %}
        {# If custom markup is provided, emit it as is #}
        {{ list_items }}
      {% endif %}
  </ul>
  {% if "su-main-nav--mobile-search" in modifier_class %}
    {% include template_path_search with
      {
        "action": mobile_search.action,
        "method": mobile_search.method,
        "search_label": mobile_search.search_label,
        "placeholder": mobile_search.placeholder,
        "search_input_name": mobile_search.search_input_name,
        "search_icon_src": mobile_search.search_icon_src
      }
      only
    %}
  {% endif %}
</nav>