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 object is active, or false if the link object is inactive.

A link is considered active if the resource it points to is part of the URL structure. For example, if the current page is /blogs/news/snowfall, then the following links are active:

  • /blogs/news, where the resource is the blog
  • /blogs/news/snowfall, where the resource is the blog article

Given the behavior of link.active, multiple links in a menu can have link.active be true at the same time, even when they have different values for link.url.

More examples

If you're on a collection page that's filtered with tags, then a link that points to the unfiltered collection page still returns true for link.active. For example, if the URL is collections/men/boots, then the following links are active:

  • collections/men, where the resource is the collection
  • collections/men/boots, where the resource is the filtered collection

If you're on a product page that's collection-aware, then link.active returns true for both the collection-aware product URL and the collection-agnostic URL. For example, if the URL is /products/awesome-product, then the following links are active:

  • /products/awesome-product
  • /collections/awesome-collection/products/awesome-product
  • /collections/all/products/awesome-product

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.

This example shows the Liquid code and output for when the "Montreal" page is being viewed on a website. The example website has a the following main menu structure:

Returns true if the page content associated with the link is considered a match to the current page. Returns false if the content isn't considered a match.

The following example shows the Liquid code and output for when the /collections/winter page is being viewed. The example website has a linklist with the following three links:

  • Summer collection, /collections/summer
  • Winter collection, /collections/winter
  • All products, /collections/all

The link.current property doesn't identify exact URL matches between the current page’s URL and a link.url value. There are two important behaviors to be aware of:

  • link.current ignores URL parameters
  • link.current treats product URLs and collection-aware product URLs as matching page content

Ignoring URL parameters

If the current page URL is /collections/winter?sort_by=price_ascending, then link.current is true for a link with a link.url of /collections/winter.

This behavior is useful because a collection link that's highlighted in a menu should remain highlighted after the collection is reordered.

Handling collection-aware product URLs

If the current page URL is /products/wool-gloves, then link.current returns true on the following link objects:

  • /collections/gloves/products/wool-gloves
  • /products/wool-gloves

This behavior is useful for reliably identifying when a product that's currently being viewed is in a menu. The content of the product page is often largely the same regardless of whether the link is collection-aware.

Returns true if a child link has a link object with link.current equal to true. Returns false if no child links have a link object with link.current equal to true.

This example shows the Liquid code and output for when the "Montreal" page is being viewed on a website. The example website has a the following main menu structure: