{% comment %} The first section creates an array of page urls that are page urls of this collection. They then are compared to all page urls in the list below. Use group in the frontmatter to group pages. {% endcomment %} {%- assign col = site.collections | where: “label”, page.collection | first -%} <nav class=“sidenav sn-contents” aria-label=“Other Pages in this Resource”>

<ul class="sidenav--list">

{%- unless col.groups -%}

{%- assign documents = col.docs -%}

{%- for p in documents -%}
  {% if forloop.first %}
    {%- assign pgs = p.url -%}
  {%- else -%}
    {%- assign pgs = pgs | append: "," | append: p.url -%}
  {%- endif -%}
{%- endfor -%}
{%- assign pgs = pgs | split: "," -%}
{%- assign my_pages = site.documents | sort: "order" -%}
{%- for my_page in my_pages -%}
  {%- unless my_page.nosidenav -%}{%- if pgs contains my_page.url -%}
  <li><a class="page-link" {% if my_page.url == page.url %} aria-current="page" {%- endif -%} href="{{ my_page.url | relative_url }}">{% if my_page.nav_title %}{{ my_page.nav_title | xml_escape }}{%- else -%}{{ my_page.title | xml_escape }}{%- endif -%}</a></li>
  {%- endif -%}{%- endunless -%}
{%- endfor -%}

{%- else -%}

{%- for group in col.groups -%}

  {%- assign documents = col.docs | where: "group", page.group -%}

  {%- unless my_page.nosidenav -%}
  {%- capture elurl %}/{{page.collection}}/{% unless group.name == "index" %}{{ group.name}}/{% endunless%}{% endcapture -%}
  <li><a class="page-link" {% if elurl == page.url %} aria-current="page" {% else %}{% if group.name == page.group %} aria-current="location" {% endif %}{%- endif %} href="{{ elurl | relative_url }}">{{group.title}}</a>
  {%- if group.name == page.group -%}
  <ul>
    {%- for p in documents -%}
      {% if forloop.first %}
        {%- assign pgs = p.url -%}
      {%- else -%}
        {%- assign pgs = pgs | append: "," | append: p.url -%}
      {%- endif -%}
    {%- endfor -%}
    {%- assign pgs = pgs | split: "," -%}
    {%- assign my_pages = site.documents | sort: "order" -%}
    {%- for my_page in my_pages -%}
      {% unless my_page.nosidenav %}{% if pgs contains my_page.url %}
      <li><a class="page-link" {% if my_page.url == page.url %} aria-current="page" {% endif %} href="{{ my_page.url | relative_url }}">{% if my_page.nav_title %}{{ my_page.nav_title | xml_escape }}{%- else -%}{{ my_page.title | xml_escape }}{%- endif -%}</a></li>
      {%- endif -%}{%- endunless -%}
    {%- endfor -%}
  </ul>
  {%- endif -%}
  </li>
  {%- endunless -%}

{%- endfor -%} {%- endunless -%}

</ul>

</nav>