Difference between revisions of "Liquid Template Variables - link"
From Spiffy Stores Knowledge Base
m (→link.links) |
m |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The | + | The Liquid template variable '''link''' has the following attributes: |
== <code>link.id</code> == | == <code>link.id</code> == | ||
Line 49: | Line 49: | ||
<pre>{% for link in linklists.gift-ideas.links %} | <pre>{% for link in linklists.gift-ideas.links %} | ||
<div> | <div> | ||
− | {{ link.object.products.first. | + | {{ link.object.products.first.featured_image | product_img_url: 'thumb' | img_tag | link_to: link.object.url }}<br /> |
{{ link.title }} | {{ link.title }} | ||
</div> | </div> | ||
Line 69: | Line 69: | ||
* search_link | * search_link | ||
* http_link | * http_link | ||
+ | |||
+ | == <code>link.css_class</code> == | ||
+ | |||
+ | Return the CSS class, if any, that has been configured for the link when it was created. | ||
== <code>link.links</code> == | == <code>link.links</code> == | ||
Line 81: | Line 85: | ||
Returns the number of child links for this link. | Returns the number of child links for this link. | ||
+ | |||
+ | == Further Reference == | ||
+ | |||
+ | * [[Liquid Basics]] | ||
+ | * [[Liquid Tag Reference]] | ||
+ | * [[Liquid Filter Reference]] | ||
+ | * [[Liquid Variable Reference]] | ||
+ | * [[Liquid Paginate Tag|Pagination ]] |
Latest revision as of 12:13, 25 June 2018
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.