{# Some collections (like "patterns") will not have any items in the alpha build for example. So this checks to make sure the collection exists. #}
{% if collections[tag] -%}
  {% set groupUrl %}/docs/{{ tag }}/{% endset %}
  <wa-details {{ ((tag in (tags or [])) or (groupUrl in page.url)) | attr('open') }}>
    <h2 slot="summary">
      {% if groupUrl | getCollectionItemFromUrl %}
        <a href="{{ groupUrl }}" title="Overview">{{ title or (tag | capitalize) }}
          <wa-icon name="grid-2"></wa-icon>
        </a>
      {% else %}
        {{ title or (tag | capitalize) }}
      {% endif %}
    </h2>
    <ul>
      {% for page in collections[tag] | sort %}
        {% if not page.data.parent -%}
          {% include 'sidebar-link.njk' %}
        {%- endif %}
      {% endfor %}
    </ul>
  </wa-details>
{%- endif %}
