Liquid reference
Liquid is a template language created by Shopify. It's available as an open source project on GitHub, and is used by many different software projects and companies.
This reference documents the Liquid tags, filters, and objects that you can use to build Shopify Themes.
Anchor to What is a template language?What is a template language?
A template language allows you to create a single template to host static content, and dynamically insert information depending on where the template is rendered. For example, you can create a product template that hosts all of your standard product attributes, such as the product image, title, and price. That template can then dynamically render those attributes with the appropriate content, depending on the current product being viewed.
Anchor to Variations of LiquidVariations of Liquid
The variation of Liquid in this reference extends the open-source version of Liquid for use with Shopify themes. It includes tags, filters, and objects that can be used to render objects specific to Shopify stores and storefront functionality.
Shopify also uses slightly different versions of Liquid to render dynamic content for the following features. These variations aren’t included in this reference.
Anchor to Liquid basicsLiquid basics
Liquid is used to dynamically output objects and their properties. You can further modify that output by creating logic with tags, or directly altering it with a filter. Objects and object properties are output using one of six basic data types. Liquid also includes basic logical and comparison operators for use with tags.
Liquid tags are used to define logic that tells templates what to do.
Tags are wrapped with curly brace percentage delimiters {% %}.
The text within the delimiters is an instruction, not content to render.
In the example to the right, the if tag defines the condition to be met.
If product.available returns true, then the price is displayed.
Otherwise, the “sold out” message is shown.
{% %}
To nest multiple tags inside one set of delimiters, use the liquid tag.
Some tags accept parameters: either required or optional.
For example, the for tag takes an optional limit parameter to stop the loop at a specific index.
Anchor to Modifying output with filtersModifying output with filters
Liquid filters modify the output of variables and objects.
To filter the output of a tag, use the pipe character |, followed by the filter.
In this example, product is the object, title is its property, and upcase is the filter.
Anchor to Filters with parametersFilters with parameters
Many filters accept parameters that adjust their output. Some parameters are required, others are optional.
Anchor to Using multiple filtersUsing multiple filters
Multiple filters can be used on one output. They're applied from left to right.
Anchor to Referencing objectsReferencing objects
Liquid objects represent variables that you can use to build your theme. Object types include, but aren't limited to:
- Store resources, such as a collection or product and its properties
- Standard content that is used to power Shopify themes, such as
content_for_header - Functional elements that can be used to build interactivity, such as
paginateandsearch
Objects might represent a single data point, or contain multiple properties. Some products might represent a related object, such as a product in a collection.
{{ }}
Double curly brace delimiters denote an output.
Anchor to UsageUsage
To output an object, wrap it in curly brace delimiters {{ }}.
To output an object's property, use dot notation.
This example outputs the product object's title property.
Anchor to Object accessObject access
Objects can be accessed in three ways:
- Globally: Available in any Liquid file, excluding checkout.liquid and Liquid asset files
- In templates: Available in specific templates and their sections or blocks. For example, the
productobject in a product template - Through parent objects: Returned as properties of other objects. For example,
articleobjects througharticlesorblog
Check each object's documentation to see how it can be accessed.
Anchor to Creating variablesCreating variables
To create your own variables, use variable tags like assign or capture.
Syntactically, Liquid treats variables the same as objects.