Navigation object

Published

All link lists created in admin are gathered in the {{ navigation }} object.

A specific link list in the navigation object can be reached with the handle, id, position or referencing a theme setting. Most commonly a theme setting is used as it enables the link lists to easily be replaced without making changes in the code.

All link lists will contain a collection of links, these all have properties.

Properties Description
id Link id
type Specifies the type of link. Values are article, blog, page, product, collection, navigation and link
param Id of the referenced object
title Title given in to the link in admin
handle Handle of the referenced object
Properties for a link object
{% for link in navigation.main.links %}
	<a href="{{ link | url }}">{{ link.title }}</a>
{% endfor %}
Example of creating links for a link list with the handle main

Nested menus

The link lists can be connected to create several levels. When developing menus or themes link.type == 'navigation' can be used to check for child link lists.

{% assign mainNav = settings.mainMenu | def: "main" %}
<ul class="space-y-2">
  {% for link in navigation[mainNav].links %}
     {% if link.type == 'navigation' %}
       <li class="font-bold">
         <details>
           <summary class="uppercase cursor-pointer py-2">{{ link.title }}</summary>
           <ul class="pl-3 space-y-1">
              {% for childlink in navigation[link.handle].links %}
              {% if childlink.type == 'navigation' %}
                <li>
                  <details>
                    <summary class="cursor-pointer">{{ childlink.title }}</summary>
                    <ul class="pl-4 space-y-1">
                    {% for subchild in navigation[childlink.handle].links %}
                      <li><a href="{{ subchild | url }}">{{ subchild.title }}</a></li>
                    {% endfor %}
                    </ul>
                  </details>
                </li>
              {% else %}
                <li><a href="{{ childlink | url }}">{{ childlink.title }}</a></li>
              {% endif %}
            {% endfor %}
          </ul>
        </details>
      </li>
    {% else %}
      <li class="font-bold"><a href="{{ link | url }}">{{ link.title }}</a></li>
    {% endif %}
  {% endfor %}
</ul>
Example of the Liquid and HTML code for a menu with multiple levels