Liquid Template Variables - link
From Spiffy Stores Knowledge Base
The Liquid template variable link has the following attributes:
Contents
link.id
Returns the unique internal number of the link.
This is normally only for internal usage.
link.title
Returns the title of this link.
link.url
The is the link's relative URL address.
link.active
This returns true or false if this link matches the current page. This is useful for testing when to apply an 'active' class style to a menu link.
The link can also be tested within nested URLs. If a product page is collection aware, then it will use a compound URL such as
/collections/some-collection/products/some-product
In this case both the links /collections/some-collection
and /products/some-product
will be flagged as active.
All tag filters will be removed, so the unfiltered collection link will always be flagged as active.
If you are on an article page, the corresponding blog link will be marked as active.
This is an example of how link.active
can be used.
{% for link in linklists.main-menu.links %} <li> <a href="{{ link.url }}"{% if link.active %} class="active"{% endif %}>{{ link.title }}</a> </li> {% endfor %}
link.object
Returns the object that the link points to, for example, a collection, a product, and so on.
This could be used to create an overview for related collections.
{% for link in linklists.gift-ideas.links %} <div> {{ link.object.products.first.featured_image | product_img_url: 'thumb' | img_tag | link_to: link.object.url }}<br /> {{ link.title }} </div> {% endfor %}
An object is not returned if the object type is frontpage_link, search_link or http_link.
link.type
Returns the type of the object in link.object.
The values returned are as follows:
- frontpage_link
- product_link
- collection_link
- page_link
- blog_link
- search_link
- http_link
link.css_class
Return the CSS class, if any, that has been configured for the link when it was created.
link.links
Returns a collection of all of this link's children.
link.level
Returns the nested level of a link in a multi-level menu. The top-most link always returns level 0.
link.links_count
Returns the number of child links for this link.