Objects
Liquid objects contain attributes to output dynamic content on the page. For example, the product
object contains an attribute called title
that can be used to output the title of a product.
Liquid objects are also often referred to as Liquid variables.
To output an object's attribute, wrap the object's name in {{
and }}
, as shown below:
{{ product.title }} <!-- Output: “Awesome Shoes” -->
Global objects
The following objects can be used and accessed from any file in your theme, and are defined as global objects or global variables.
all_products
The all_products object contains a list of all the products in your store.
{{ all_products['wayfarer-shades'].title }}
canonical_url
The canonical_url
object returns the canonical URL for the current page. The canonical URL is the page's "default" URL with any URL parameters removed.
For products and variants, the canonical URL is the default product page with no collection or variant selected. For example, for a product in a collection with a variant selected:
https://docksupply.co/collections/products/dory-shoes?variant=17287731270
https://docksupply.co/products/dory-shoes
collections
The collections
object returns all the collections in your store
{% for product in collections.frontpage.products %}
{{ product.title }}
{% endfor %}
current_tags
The current_tags
object will return a different list of tags depending on the template that is being rendered.
<!-- in blog.liquid -->
{% if current_tags %}
<h1>{{ blog.title | link_to: blog.url }} › {{ current_tags.first }}</h1>
{% else %}
<h1>{{ blog.title }}</h1>
{% endif %}
Caution
current_tags
can only used incollection.liquid
.
customer
The customer
object returns the customer that is logged in to the store. It will not return anything if a customer isn't logged in
{% if customer.id %}
<a href="/account/order">{{ 'i18n.navigation.general.my_orders' | t }}</a>
<a href="/account/addresses">{{ 'i18n.navigation.general.address_book' | t }}</a>
{% else %}
<a href="/account/login">{{ 'i18n.navigation.general.login' | t }}</a>
<a href="/account/register">{{ 'i18n.navigation.general.register' | t }}</a>
{% endif %}
linklist
The linklists
object returns the set of the menus and links in your store. You can access a menu by calling its handle on the linklists
object
<ul>
{% for link in linklists.categories.links %}
<li>{{ link.title | link_to: link.url }}</li>
{% endfor %}
</ul>
images
The images
object lets you access any image in your store by its filename
{% assign image = images['my-image.jpg'] %}
<img src="{{ image }}" alt="{{ image.alt }}">
page_description
The page_description
object returns the description of the product, collection, or page that is being rendered. Descriptions for these items can be set in your Shoplazza admin
{% if page_description %}
<meta name="description" content="{{ page_description }}" />
{% endif %}
page_title
The page_title
object returns the title of the current page.
shop
The shop
object contains information about your store.
settings
The settings
object lets you access the settings of a store's published theme.
{% if settings.logo %}
{{ settings.logo | img_url | img_tag: shop.name }}
{% else %}
<span class="no-logo">{{ shop.name }}</span>
{% endif %}
template
The template object returns the name of the template that is being used to render the current page, not including its .liquid
file extension. As a best practice, it's recommended that you apply the template name as a CSS class on your HTML <body>
tag. More info ›
<body class="{{ template }}">
theme
The theme
object returns the store's published theme.
Visit the <a href="/admin/themes/{{ theme.id }}/settings">theme editor</a>.
Content objects
The following objects are used to output the content of template and section files, as well as the scripts and stylesheets loaded by Shoplazza and Shoplazza apps.
content_for_header
The content_for_header
object is required in theme.liquid. It must be placed inside the HTML tag. It dynamically loads all scripts required by Shoplazza into the document head. These scripts include Shoplazza analytics, Google Analytics, and scripts required for Shoplazza apps.
You shouldn't try to modify or parse the content_for_header object. If content_for_header changes, then the behavior of your Liquid will change. Modifications to content_for_header can lead to broken analytics information within Shoplazza and other analytics programs with officially supported integration paths.
content_for_layout
The content_for_layout
object is required in theme.liquid. It must be placed inside the HTML <body>
tag. It dynamically loads content generated by other templates such as index.liquid
or product.liquid
.
Updated over 2 years ago