The link object

The link object cannot be invoked on its own. It must be invoked inside a linklist.

The link object has the following attributes:

Returns true if the link is active, or false if the link is inactive.

If you are on a product page that is collection-aware, link.activewill return true for both the collection-aware product URL and the collection-agnostic URL. For example, if you have a link whose URL points to:

/products/awesome-product

link.active will return true for the following URL, which links to the same product but through a collection:

/collections/awesome-collection/products/awesome-product

If you are on a collection page filtered with tags, and the link points to the unfiltered collection page, link.active will return true.

If you are on an article page and your link points to the blog, link.active will return true.

Similar to link.active, but returns true if a child link of the parent link is active, or false if no child links of the parent link are active.

Input

{% assign menu = linklists.main-menu %}

{{ menu.title }}
{% for link in menu.links %}
  {{ link.title }}: active: {{ link.active }}, child_active: {{ link.child_active }}
  {% for sub_link in link.links %}
    {{ sub_link.title }}: active: {{ sub_link.active }}, child_active: {{ sub_link.child_active }}
    {% for sub_sub_link in sub_link.links %}
      {{ sub_sub_link.title }}: active: {{ sub_sub_link.active }}, child_active: {{ sub_sub_link.child_active }}
    {% endfor %}
  {% endfor %}
{% endfor %}

Output

Main Menu
  Home: active: false, child_active: false
  About Us: active: false, child_active: true
    In the news: active: false, child_active: false
    Locations: active: false, child_active: true
      Montreal: active: true, child_active: false
      Ottawa: active: false, child_active: false

Returns the number of nested levels that a link contains.

For example, given the following main menu structure:

Main Menu
  └ Home
  └ About Us
    └ Locations
      └ Montreal
      └ Ottawa

The following Liquid code:

{% assign menu = linklists.main-menu %}

{{ menu.title }}: {{ menu.levels }}
{% for link in menu.links %}
  {{ link.title }}: {{ link.levels }}
  {% for sub_link in link.links %}
    {{ sub_link.title }}: {{ sub_link.levels }}
    {% for sub_sub_link in sub_link.links %}
      {{ sub_sub_link.title }}: {{ sub_sub_link.levels }}
    {% endfor %}
  {% endfor %}
{% endfor %}

produces the following output (edited for space):

Main Menu: 3
  Home: 0
  About Us: 2
    Locations: 1
      Montreal: 0
      Ottawa: 0

Returns an array of the child links associated with the parent link.

Returns the variable associated to the link. The possible types are:

Through link.object, you can access any of the attributes that are available in the above three variables.

Input

<!-- If the product links to a product with a price of $10 -->
{{ link.object.price | money }}

Output

$10

Returns the title of the link.

Returns the type of the link. The possible values are:

  • collection_link: if the link points to a collection
  • product_link: if the link points to a product page
  • page_link: if the link points to a page
  • blog_link: if the link points to a blog
  • search_link: if the link points to the search page /search
  • frontpage_link: if the link points to the home page /home
  • catalog_link: if the link points to the catalog page /collections
  • collections_link: if the link points to the all collections page /collections/all
  • http_link: if the link points to an external web page, or a type or vendor collection (ex: /collections/types?q=Pants)

Returns the URL of the link.

Ready to start selling with Shopify?

Try it free