link
A link in a menu.
To learn about how to implement navigation in a theme, refer to Add navigation to your theme.
Properties
Returns
true
if the link is active. Returnsfalse
if not.A link is considered to be active if the current URL path matches, or contains, the link's url. For example, if the current URL path is
, then the following link URLs would be considered active:
TipThe
link.active
property is useful for menu designs that highlight when top-level navigation categories are being viewed. For example, if a customer is viewing an article from the "Potion notions" blog, then the "Potion notions" link is highlighted in the menu.Returns
true
if a link's child link is active. Returnsfalse
if not.A link is considered to be active if the current URL path matches, or contains, the URL of the link.
For example, if the current URL path is
, then the following link URLs would be considered active:
Returns
true
if current URL path matches a link's child link URL. Returnsfalse
if not.NoteURL parameters are ignored when determining a match.
Product URLs within the context of a collection and standard product URLs are treated the same.
Returns
true
if the current URL path matches the URL of the link. Returnsfalse
if not.NoteURL parameters are ignored when determining a match.
Product URLs within the context of a collection are treated as equal to a standard product URL for the same product.
The child links of the link.
ExampleCheck the number of links{% for link in linklists.main-menu.links -%}{% if link.links.size > 0 -%}- {{ link.title }} ({{ link.links.size }} children)<br>{%- else -%}- {{ link.title }}<br>{%- endif %}{%- endfor %}{% for link in linklists.main-menu.links -%} {% if link.links.size > 0 -%} - {{ link.title }} ({{ link.links.size }} children)<br> {%- else -%} - {{ link.title }}<br> {%- endif %} {%- endfor %}
{ "linklists": { "main-menu": { "links": [ "LinkDrop", "LinkDrop", "LinkDrop" ] } } }
Output
- Home<br>- Catalog (2 children)<br>- Contact<br>- object
The object associated with the link.
The object can be one of the following:
The type of the link.
Possible values Description article_link The link points to an article. blog_link The link points to an blog. catalog_link The link points to the catalog page. collection_link The link points to a collection. collections_link The link points to the collection list page. customer_account_page_link The link points to a customer account page. frontpage_link The link points to the home page. http_link The link points to an external web page, or a product type or vendor collection. metaobject_link The link points to a metaobject page. page_link The link points to a page. policy_link The link points to a policy page. product_link The link points to a product page. search_link The link points to the search page.
{
"active": false,
"child_active": false,
"child_current": false,
"current": false,
"handle": {},
"levels": 0,
"links": [],
"object": {},
"title": {},
"type": "page_link",
"url": "/pages/contact"
}