Blog / Build with AI /
Shopify Liquid explained for AI builders
You open a Shopify theme file and it’s HTML, but with odd curly brackets sprinkled through it: {{ product.title }}, {% if ... %}, {% for ... %}. You ask an AI to “change the product page so it shows a badge when the item is on sale” and it hands you a snippet of the same strange language.
That language is Liquid. If you want to build anything with Shopify and AI, you’ll meet it on day one. The good news is you only need a small slice of it, and you can read it like a template for a letter.
What Liquid is
Liquid is the template language Shopify uses to turn your store’s data into web pages. A template says “put the product’s name here, its price there, and show this banner only if it’s on sale”. When a visitor asks for a page, Shopify fills in the blanks with real data and sends back plain HTML.
Think of a mail-merge letter. “Dear {{ name }}” becomes “Dear Amina” when the letter is printed. Liquid does the same for web pages, with more rules.
Because Liquid runs on Shopify’s servers before the page is sent, visitors never see it. They just see the finished page. (Browser code, JavaScript, is a separate thing that runs after.)
The three kinds of curly bracket
Nearly everything in Liquid comes in three forms:
| Form | Name | What it does |
|---|---|---|
{{ ... }} |
Output | Prints a value on the page |
{% ... %} |
Tag | Controls logic: if, for, assign |
{{ value \| filter }} |
Filter | Changes a value before printing |
Output: show something
<h1>{{ product.title }}</h1>
product is an object, a bundle of information about the current product. .title reads one property of it. The page prints the title.
Tags: make decisions and repeat
{% if product.available %}
<button>Add to cart</button>
{% else %}
<p>Sold out</p>
{% endif %}
Reads like English: if the product is available, show the button; otherwise say sold out. Every if needs an endif.
Looping works the same way:
<ul>
{% for variant in product.variants %}
<li>{{ variant.title }}</li>
{% endfor %}
</ul>
For each variant of the product, print a list item.
Filters: tidy up a value
{{ product.price | money }}
{{ product.title | upcase }}
{{ product.description | strip_html | truncate: 120 }}
The pipe | passes the value through a filter, a bit like an assembly line. money formats the price using the store’s currency settings. strip_html removes HTML tags, and truncate: 120 shortens the text to 120 characters. Filters chain from left to right.
Objects you’ll see everywhere
You don’t need the full list. These show up constantly:
product: the current product (title, price, images, variants, description).collection: the current collection and its products.cart: what the visitor has in their basket.shop: store-level details such as the name.page_title,request,settings: page and theme details.
When you’re not sure what’s available, ask the AI: “What properties does the product object have in Shopify Liquid?” and then check Shopify’s official Liquid reference, because that’s the source of truth and it’s updated more reliably than anyone’s memory, human or machine.
Where Liquid lives in a theme
A Shopify theme is a set of folders. The ones that matter to you:
- layout: the outer frame (header, footer) shared by every page.
- templates: one per page type (product, collection, cart). Newer themes often use JSON templates that list which sections appear.
- sections: bigger reusable blocks, usually customisable in the theme editor.
- snippets: small pieces included from other files.
- assets: CSS, JavaScript and images.
- config and locales: theme settings and translations.
If you’re about to edit a theme, duplicate it first. Work on the copy. That single habit prevents most disasters. For the SEO side of changing templates, what to check when changing Shopify theme templates is useful.
Working with AI on Liquid
AI is decent at Liquid, with a few cautions.
Give it context
Paste the section or snippet you’re changing and say what you want:
Here is my product-card snippet. Add a “Sale” badge when compare_at_price is higher than price. Keep the existing markup and classes. Only show the badge on available products. Explain each change.
“Keep the existing markup” stops it from rewriting everything. “Explain each change” lets you learn.
Check the pieces it invents
AI can write convincing Liquid that uses objects or filters that don’t exist, or that exist in another platform’s template language. If the result throws an error or prints nothing, say what you see. Ask it to point to the Liquid documentation for any filter it used. The same habit applies in code generally; AI hallucinations in code: spotting invented functions covers it.
Keep Liquid and JavaScript apart in your head
A common mix-up: asking for something that needs to react to a click (open a menu, update a price when a variant changes). That’s JavaScript’s job, running in the browser. Liquid only prepares the page; it can’t respond afterwards. A good prompt says which side you’re asking for.
Test on a copy, on real products
View a product that’s on sale, one that’s sold out, one with many variants, and one with no image. Edge cases are where template bugs live. Check mobile as well as desktop.
Common beginner mistakes
- Forgetting the closing tag: every
ifneedsendif, everyforneedsendfor. - Comparing text with the wrong case or spelling:
"Sale"and"sale"differ. - Assuming a value exists. An empty image or a missing field prints nothing, or breaks layout. Check with
{% if ... %}first. - Leaving app code behind. Removing an app doesn’t always remove the code it added to your theme. See removing leftover app code from a Shopify theme.
- Editing the live theme. Always work on a duplicate.
Why it matters for SEO and speed
Liquid controls the HTML Shopify sends: title tags, headings, canonical tags, structured data. A small template edit can change all of them across hundreds of pages, which makes it powerful and risky. After any change, view the page source and check titles, headings and structured data on a few templates. Heavy loops and large images in a template can slow pages down too.
Key takeaways
- Liquid is a template language: output with
{{ }}, logic with{% %}, tidying with filters. - It runs on Shopify’s servers and produces plain HTML.
- Learn objects like
product,collectionandcart. - Duplicate the theme before editing.
- Give AI the real code and context, and verify anything it invents.
FAQ
Do I need to learn Liquid fully?
No. Reading it and making small edits is enough for most store owners.
Is Liquid only for Shopify?
Shopify created it and uses it most; some other tools use it too, with differences.
Can AI write a whole theme?
It can help with parts, but a whole theme needs testing across pages, devices and apps. Treat its output as a draft.
Related reading
What’s one thing on your product page you’d like to change if you weren’t afraid of the code?