Hello! Welcome back to our module on Liquid Templating.
In our last lesson, we answered the "why" behind Liquid, establishing that it's a sandboxed, server-side templating language designed for security and control in Shopify's multi-tenant environment. We now have the foundational context for why Shopify uses this specific tool.
Today, we transition from the "why" to the "how." Our learning outcome is to use Liquid syntax (objects, tags, and filters) to display dynamic data and implement logic. You'll find that the core programming concepts—variables, loops, and conditionals—are very familiar from your experience with JavaScript. Our focus will be on mastering Liquid's unique syntax for these operations.
By the end of this lesson, you'll be able to read and write basic Liquid code to pull data from a Shopify store and render it on a page.
The Three Pillars of Liquid Syntax
At its core, Liquid syntax is composed of three main elements: objects, tags, and filters. Understanding how these three components work together is the key to unlocking theme development.
Let's get a formal introduction to each.
An Overview of Liquid: Shopify's Templating Language
The Shopify Partners blog post, "An Overview of Liquid", provides clear, concise definitions for these core concepts. We'll use it to establish our foundational knowledge.
Please read the following sections: Start with 'Liquid's file extension and delimiters' to understand the two main syntaxes. Read 'Output' and 'Objects and properties' to learn about {{ }} and how data is structured. Read 'Liquid filters' to understand how the pipe | character is used to modify data. Finally, read 'Liquid logic' and 'Operators' to see how {% %} is used for control flow.
To summarize and visualize what you've just read:
- Objects
{{ }}: These are for output. They act as placeholders that print data from your store. The data is accessed using dot notation, similar to accessing properties of a JavaScript object (e.g.,{{ product.title }}). - Tags
{% %}: These are for logic. They don't produce visible output themselves but control the flow of your template. This includes conditionals (if,else), loops (for), and variable assignments (assign). - Filters
|: These are simple functions used to modify the output of an object. They are placed within an output tag{{ }}and are separated from the object by a pipe character (|). You can chain multiple filters together.
Now, let's watch a quick video that recaps these three concepts visually.
This clip from the "Understanding Shopify Liquid" video by Coding with Jan gives a perfect, high-level summary of objects, filters, and tags.
Watch the segment from 03:15 to 05:34. Notice how he clearly distinguishes the syntax and purpose of each of the three components.
Putting It All Together: From Syntax to Storefront
Now that we have the basic syntax, let's apply it. The best way to learn is by working with real store data. We're going to build a common e-commerce component: a list of products.
The following video is a crash course that walks through writing Liquid from scratch. Since you're already a programmer, this fast-paced, hands-on approach should be effective. We will focus on the parts where we interact with actual Shopify data.
SHOPIFY LIQUID: Theme Programming for Beginners [CRASH COURSE]
We'll use Chris the Freelancer's "SHOPIFY LIQUID: Theme Programming for Beginners" video as a guide. It moves quickly from basic syntax to a practical example using real store data.
Watch from 16:38 to 26:59. This extended segment is the core of our lesson. Follow along as he: Accesses a global object (collections) to get store data. Uses a for tag to loop through the products within that collection. Outputs product data like product.title and product.price. Applies a filter (money) to format the price correctly. Uses a conditional tag (unless) to add a "Sold Out" label based on product availability. Pay close attention to how the three pillars—objects, tags, and filters—work in concert to produce a dynamic list.
This video demonstrates the most common pattern in theme development:
- Access a top-level data object (like a collection).
- Loop through its items (like products).
- For each item, display its properties, applying filters for formatting and using conditional tags for logic.
The term "drop" that the video mentions (e.g., ProductDrop) is Shopify's internal name for the objects made available to Liquid. For our purposes, you can simply think of a "drop" as a "Liquid object."
Test your understanding!
You need to display a list of vendors for a given collection. The collection object has a property called all_vendors which is an array of vendor names.
Write a Liquid snippet that creates an unordered list (<ul>) of all vendors in the collection.all_vendors array. Each vendor name should be a list item (<li>).
Show answer
<ul>
{% for vendor in collection.all_vendors %}
<li>{{ vendor }}</li>
{% endfor %}
</ul>
This solution uses a for tag to iterate through the collection.all_vendors array and an output tag {{ vendor }} to print each vendor's name inside a list item.
Connecting Liquid to Your React Background
In your experience with React and Next.js, you're used to components receiving data from different sources—sometimes as props passed down from a parent, other times fetched from an API or a CMS. Liquid has a similar paradigm.
Content in a Shopify theme comes from two primary sources:
-
Native Shopify Data: These are the global objects that Shopify makes available automatically based on the context of the page. For example, on a product page, you have access to the
productobject. On a collection page, you get thecollectionobject. This is analogous to how Next.js might provide page-specific data viagetServerSidePropsor route parameters. You don't have to "fetch" this data; Shopify provides it. -
Theme Editor Settings: This is data that the merchant enters through the theme customization interface. As a developer, you define what settings are available using a
{% schema %}block in your section files. This is very similar to defining fields in a headless CMS and then fetching that data to populate your React components.
This distinction is crucial for building flexible themes.
Liquid for Next.js and React Developers
The article "Liquid for Next.js and React Developers" directly addresses this concept from a perspective you'll find familiar.
Please read the section titled 'Two Ways to Add Content: Native Data and Theme Settings'. It does an excellent job of distinguishing these two data sources and provides clear examples of how to access each.
We will dive deep into creating {% schema %} blocks and building customizable sections in Module 5, but understanding this separation of data sources now is key to forming a correct mental model.
Conclusion
Today we've demystified Liquid's syntax, breaking it down into its three core components. You now know how to use these building blocks to create dynamic templates.
Key Takeaways:
- Liquid syntax revolves around three pillars:
- Objects
{{ }}for outputting data (e.g.,{{ product.title }}). - Tags
{% %}for logic and control flow (e.g.,{% for %},{% if %}). - Filters
|for modifying output (e.g.,{{ product.price | money }}).
- Objects
- The most common workflow is to loop through a collection of objects (like products) and output their properties, using filters for formatting and tags for conditional logic.
- Data in Liquid comes from two main sources: native Shopify objects provided by context, and merchant-defined settings from the theme editor schema.
In our next lesson, we will continue our exploration of filters. We'll move beyond the money filter and look at a wider range of common and powerful filters used to manipulate strings, numbers, and dates, giving you finer control over your theme's output.