Shopify Liquid: How It Works in a Real Theme
Shopify Liquid explained by a working developer: objects, tags and filters, theme file anatomy, scope, the quirks that break stores and a path to learn it.
The short answer
Shopify Liquid is the template language every Shopify theme is written in. It runs on Shopify's servers, reads store data (products, collections, the cart, metafields) and prints HTML before the page reaches the browser. It has three parts: objects that hold data, tags that control logic, and filters that transform output. It cannot call external APIs, write data or react to clicks; that is JavaScript's job.
If you understand those limits and the file structure of a theme, you can read any Shopify storefront. This guide is the mental model I wish someone had handed me before my first production theme.
Where Liquid runs, and what it cannot do
A request for /products/linen-shirt hits Shopify. Shopify picks the template for that URL, renders the Liquid with the data for that product, and sends finished HTML. The browser never sees a single Liquid tag.
That has consequences people learn the hard way:
- No external calls. Liquid cannot fetch your ERP, a reviews API or a shipping quote. If data is not in Shopify (products, metafields, metaobjects, settings), Liquid cannot see it. Put it in a metafield or fetch it with JavaScript.
- No writes. Liquid cannot change a product, tag a customer or update inventory. Cart changes go through forms or the Ajax API from the browser.
- No per-click logic. Liquid renders once per request. Variant switching, cart drawers and quantity steppers are JavaScript that either patches the DOM or asks Shopify to re-render a section with the Section Rendering API (
?sections=section-id). - Output can be cached. Anything time-based, like
{{ 'now' | date: '%H:%M' }}, reflects when the Liquid was last rendered, not when the visitor arrived. Shopify's own docs say the timestamp might not update on every page view. Do not build a countdown timer in Liquid.
Once you accept that Liquid is a server-side templating layer and nothing more, most "why doesn't this work" questions answer themselves.
Objects, tags and filters
Every line of Liquid is one of three things.
Objects hold data and print with double curly braces. Tags do logic and use {% %}. Filters change output and chain with a pipe.
{% if product.available %}
<h1>{{ product.title | escape }}</h1>
<p>{{ product.price | money }}</p>
{% else %}
<p>{{ 'products.product.sold_out' | t }}</p>
{% endif %}
product is an object. if is a tag. escape, money and t are filters. Prices in Liquid are stored in the currency's smallest unit (cents for USD), which is why you always pass them through a money filter instead of printing the raw number.
The full list is in Shopify's Liquid reference. I keep a shorter, opinionated version in the Shopify Liquid cheat sheet.
How a theme is put together
Liquid makes more sense once you know which file is doing what. A modern Online Store 2.0 theme has this shape:
layout/theme.liquid the HTML shell: head, header group, footer group
templates/product.json which sections appear on product pages, and their settings
sections/main-product.liquid a section: markup plus a {% schema %} of settings
blocks/ theme blocks, reusable across sections
snippets/price.liquid partials, called with {% render %}
assets/ CSS, JS, images
config/settings_schema.json global theme settings definition
locales/en.default.json translation strings for the t filter
The layout wraps everything. The content_for_header object in the layout is required: Shopify injects its own scripts, analytics and app embeds through it, so never remove it. The template (usually JSON) lists sections. Sections contain blocks. Snippets are reusable partials.
JSON templates can render up to 25 sections, each section can hold up to 50 blocks, and a theme can contain up to 1,000 JSON templates. Those limits come from Shopify's JSON template docs and they matter when a merchant builds a long landing page in the editor. I cover the JSON side in depth in Shopify Online Store 2.0 and JSON templates.
Scope: which objects exist where
Not every object is available everywhere. Some are global: shop, cart, customer, settings, request, routes. Others exist only on their template: product on product pages, collection on collection pages, article on blog posts.
Inside a section you get section.settings. Inside a block loop you get block.settings. Inside a snippet called with render, you get almost nothing: render isolates variables, so anything the snippet needs must be passed in.
{% render 'product-card', product: product, show_vendor: section.settings.show_vendor %}
The older include tag let snippets read and modify outside variables. Shopify has deprecated it because that sharing hurts performance and makes code hard to follow. If you inherit a theme full of include, convert to render file by file and pass variables explicitly. It is tedious and it removes a whole class of "where did this variable come from" bugs.
The quirks that bite in production
These are the Liquid behaviours that have cost me the most time on real stores.
Only `nil` and `false` are falsy. An empty string is truthy. {% if product.metafields.custom.subtitle %} can be true for a metafield that exists but is empty. Use != blank when you mean "has content":
{% if product.metafields.custom.subtitle.value != blank %}
<p class="subtitle">{{ product.metafields.custom.subtitle.value }}</p>
{% endif %}
Conditions evaluate right to left, and parentheses are not supported. {% if a or b and c %} is not what your instinct says. Split complex conditions into nested if blocks or assign intermediate booleans.
It is `elsif`, not `elseif` or `else if`. A typo here does not always throw a visible error. It just renders the wrong branch.
`collection.products` returns 50 items by default. Without a paginate tag, a loop over a collection fetches up to 50 products, no matter what limit you set. Wrap it in paginate with a page_size between 1 and 250 if you need more on one page.
`all_products` is capped at 20 unique handles per page. Hardcoding all_products['some-handle'] in a mega menu works on the first 20 and silently fails after. Use a product list setting or a collection instead.
Whitespace adds up. Large loops output a lot of blank lines. Use {%- and -%} to trim, and the {% liquid %} tag for logic-heavy blocks:
{%- liquid
assign on_sale = false
if product.compare_at_price > product.price
assign on_sale = true
endif
-%}
Escape what merchants type. Product titles, metafield text and setting values can contain quotes and angle brackets. | escape in attributes avoids broken markup.
Performance: Liquid is cheap until it is not
Liquid renders fast for normal templates. It gets slow when someone nests loops over large arrays: every product in a collection, times every variant, times every tag, to compute a badge. I have seen product grids where one card did more Liquid work than the rest of the page combined.
Two tools help:
shopify theme checklints the theme against Shopify's best practices, including deprecated tags and missingrenderarguments.shopify theme profileprofiles Liquid render time on a given page, so you can see which section is slow instead of guessing.
The usual fixes are to precompute data into metafields, move per-variant logic to the browser, and stop looping over collections inside product cards. If you want the measured version of this, my write-up on Shopify speed optimization and Core Web Vitals walks through a real audit.
A learning path that works
If you are a developer new to Shopify, or a store owner who wants to read the code they pay for, this is the order I recommend.
1. Run a theme locally. Install Shopify CLI, then shopify theme init to clone Shopify's Skeleton theme, or shopify theme pull from an existing store. Run shopify theme dev against a development store and edit with live reload.
2. Read one product section end to end. Open the main product section of Horizon or Dawn and trace how variants, price and the buy button render. Most store customizations live on this page.
3. Add a section of your own. Build a small section with a {% schema %}, two settings and a preset. That teaches you how merchants interact with your code through the theme editor.
4. Touch metafields. Create a product metafield definition in Settings > Custom data, fill it on a product, and render it. Most real feature requests are "show this extra data on the product page".
5. Lint before you ship. Run shopify theme check, then push to an unpublished theme with shopify theme push --unpublished and preview before publishing.
When Liquid is the wrong tool
Some problems look like theme problems and are not. Discount logic belongs in Shopify Functions. Checkout changes belong in checkout extensions. Data that needs to come from another system belongs in metafields fed by an integration, not in Liquid. And if a page needs a fully custom front end, that is the Hydrogen versus Liquid decision, not a bigger theme.
Knowing where Liquid stops is half of writing good Liquid.
Custom Liquid sections, PDP rebuilds and theme refactors are the bulk of the theme work I do for brands in the US and Europe. If your theme has grown into something nobody wants to touch, that is the kind of cleanup I take on through Shopify expert development.
I build and refactor Shopify themes in Liquid for production stores. See [Shopify expert development](/shopify-expert) or [hire a Shopify developer](/hire-shopify-developer). Related: [Shopify Liquid cheat sheet](/blog/shopify-liquid-cheat-sheet), [Custom Liquid sections in Shopify](/blog/shopify-custom-liquid-section).
Direct: [WhatsApp +55 11 98851-2788](https://wa.me/5511988512788) · [contact@matheusabrahao.com](mailto:contact@matheusabrahao.com)
Need a senior engineer who thinks like an operator?
I take on a small number of Shopify operations and senior engineering engagements each quarter. If your store needs catalog hygiene, technical SEO, performance or marketing automation done right, let’s talk.
Continue reading
Shopify Plus Pricing: What It Really Costs in Year One
Shopify Plus pricing in plain numbers: the $2,300 floor, 1- and 3-year terms, the variable platform fee, and the app, build and checkout costs behind year one.
Upgrading Shopify to Shopify Plus: What Changes and What to Do
What Shopify Plus is, how upgrading from Shopify to Shopify Plus works on your existing store, and the 90-day build sequence that makes the new plan pay back.