BlogShopify development

Shopify Liquid cheat sheet and guide: syntax, tags, filters and objects

Shopify Liquid is the template language Shopify themes use to turn store data into HTML. This page gives you a cheat sheet of its syntax, tags, filters, objects and comments, then the patterns and checks that keep theme code working.

Work with Ecompanda
Copy as MarkdownSet as Preferred Source
Flat illustration of stacked white template tiles framed by two large curly braces on a deep green background

Shopify Liquid in short

Generated by Ecompanda AI

Liquid is the template language Shopify created for themes, and it runs on Shopify's servers before the browser sees the page. You print data with objects in double curly braces, add logic with tags, and change values with filters.

  • Objects in {{ }} print data, tags in {% %} add logic, filters after a pipe change a value
  • Only nil and false are falsy, so test empty text with blank
  • Use render for snippets because include is deprecated
  • A for loop stops at 50 items, so use paginate for more
  • Run Theme Check before you publish

Shopify Liquid is the template language Shopify created to build themes. Liquid markup lives in .liquid files and runs on Shopify's servers, turning store data into the HTML a shopper sees. It has three building blocks: objects in {{ }} print data, tags in {% %} add logic, and filters after a pipe | change a value.

Below is a cheat sheet you can keep open while you edit. After it come the parts that trip people up: what counts as empty, how snippets see variables, loop limits, and the stricter parser Shopify switched on in January 2026. Every row matches Shopify's own Liquid reference.

Shopify Liquid cheat sheet

The tables cover the syntax people look up most. Each filter below comes with a small working example.

Liquid template syntax

SyntaxWhat it doesExample
{{ }}Prints a value on the page{{ product.title }}
{% %}Runs an instruction (a condition, a loop, a render). The tag text itself never shows on the page{% if product.available %}
{%- -%} and {{- -}}Strips the whitespace on the side that has the hyphen{%- if cart.item_count > 0 -%}
{% liquid %}Runs many tags in one block, one per line, without delimitersSee the comment example below
{% comment %} {% endcomment %}Block comment. Nothing inside is output{% comment %} Old banner {% endcomment %}
{% # note %}Inline comment inside a single tag{% # hide until launch %}
{% raw %} {% endraw %}Shows Liquid code as text instead of running it{% raw %}{{ product.title }}{% endraw %}

Liquid tags: logic, loops and variables

TagUse it toExample
if, elsif, elseShow something when a condition is true{% if product.available %} In stock {% endif %}
unlessShow something unless a condition is true{% unless customer %} Log in {% endunless %}
case, whenPick one branch by value{% case block.type %} {% when 'image' %}
forRepeat for each item, up to 50{% for item in cart.items %}
limit, offset, reversedChange how many items a for loop shows, and in what order{% for p in collection.products limit: 4 %}
break, continueStop a loop, or skip to the next item{% break %}
paginateSplit a long list across pages{% paginate collection.products by 24 %}
assignCreate a variable{% assign on_sale = true %}
captureSave rendered output as a string{% capture heading %}{{ shop.name }} news{% endcapture %}
echoPrint a value inside a liquid tagecho product.title
renderOutput a snippet with its own scope{% render 'price', variant: variant %}
content_forMark where theme blocks appear in a section{% content_for 'blocks' %}
docDocument the parameters a snippet expects{% doc %} @param {object} variant {% enddoc %}

Conditions use ==, !=, >, <, >=, <=, and, or and contains. That's the full list on the basics page. There is no && or ||, and you can't group conditions with parentheses.

Common Liquid filters

  • upcase, downcase, append and truncate change text: {{ product.title | truncate: 40 }}
  • escape makes text safe inside HTML: {{ block.settings.title | escape }}
  • money and money_with_currency format a price with the store's currency settings: {{ product.price | money }}
  • default gives a fallback when a value is nil, false or empty: {{ product.selected_variant.url | default: product.url }}
  • image_url and image_tag get an image at a set size, then build the <img>: {{ product.featured_image | image_url: width: 600 | image_tag }}
  • date formats a timestamp: {{ article.created_at | date: '%B %d, %Y' }}
  • t prints text from the theme's locale files: {{ 'products.product.add_to_cart' | t }}
  • where, find, reject and size work on arrays: {{ collection.products | where: 'vendor', 'Acme' | size }}
  • json prints any value as JSON, which is handy while debugging: {{ product.tags | json }}

Shopify objects you will use most

ObjectWhat it holdsProperties you will reach for
productA product in the storetitle, price, variants, featured_image, selected_or_first_available_variant
variantOne variant of a productprice, compare_at_price, available
collectionA collectiontitle, url, products, products_count
cartThe shopper's cartitem_count, items, total_price
sectionThe current sectionid, settings, blocks, index
blockOne block inside a sectiontype, settings, shopify_attributes
settingsTheme settings from settings_schema.jsonsettings.your_setting_id
shopThe store itselfname
customerThe logged-in customer, nil when nobody is logged infirst_name
requestThe current URL and pagepage_type, design_mode
all_productsAny product, looked up by handleall_products['handle'], up to 20 unique handles per page

Each object has its own page under Objects in the reference, with every property and its type.

How do you write a comment in Liquid?

Wrap a block comment in {% comment %} and {% endcomment %}, or write an inline comment as {% # your note %}. Nothing inside a comment is output. Liquid inside a block comment is parsed but not run.

{% comment %}
  Old holiday banner. Keep the markup for next year.
{% endcomment %}

{% # show the badge only on sale items %}

{%- liquid
  # inside a liquid tag, a comment line starts with #
  assign on_sale = false
-%}

Two rules catch people out. The comment tag reference says a multi-line inline comment needs a # at the start of every line. And the strict parser guide says a comment inside a liquid tag must sit on its own line, not after code.

What is Shopify Liquid?

Liquid is a template language created by Shopify. The core is an open source project written in Ruby and used by other software too. Shopify's theme version adds the tags, filters and objects that are specific to stores.

The Liquid reference overview page on shopify.dev, with Basics, Tags, Filters and Objects in the left sidebar
Shopify's Liquid reference is the source for every tag, filter and object in the cheat sheet

A template language lets one file serve many pages. Your product template describes the page once. Liquid then fills in the title, images and price of whichever product the shopper is viewing.

One catch. Shopify runs slightly different versions of Liquid for notification emails, Shopify Flow and order printer templates, and the theme reference does not cover them. So a tag that works in your theme may fail in an email template.

How Shopify turns Liquid into a page

A theme is a set of files that Shopify assembles in layers. The theme architecture page puts it this way: the layout is the base, the template controls what a page shows, sections are modules the template lists, blocks sit inside sections, and snippets are reusable pieces you can render anywhere.

Nested boxes showing a layout containing a template, which contains a section, which contains a block, which contains a snippet
How one page is assembled on the server: layout, template, section, block and snippet, original diagram, Ecompanda

Two details matter when you edit:

  • layout/theme.liquid must contain {{ content_for_header }} and {{ content_for_layout }}. The layouts page says that without them you can't save the file in the code editor or Shopify CLI.
  • A JSON template is data, not code. It lists sections and their order, and it can render up to 25 sections with up to 50 blocks each. A Liquid template holds code.

All of this runs before the browser sees anything. Shopify's performance guide says Liquid renders server-side on every page request, and that time directly sets Time to First Byte. So slow Liquid means a slow page, whatever your images weigh.

Objects, tags and filters in practice

Objects and handles

Objects expose properties with dots. Resources with a handle, such as pages, can also be read with square brackets, which helps when the handle has a hyphen:

<h1>{{ product.title | escape }}</h1>
<p>{{ product.vendor }}</p>
<a href="{{ pages['about-us'].url }}">About us</a>

Truthy, falsy and blank

In Liquid only nil and false are falsy. The basics page lists the results:

ValueTreated as
nil (missing value)falsy
falsefalsy
Empty stringtruthy
0truthy
Empty arraytruthy

So {% if section.settings.heading %} passes when the merchant left the heading empty. Compare with blank instead:

{% if section.settings.heading != blank %}
  <h2>{{ section.settings.heading | escape }}</h2>
{% endif %}

Operators are evaluated from right to left, and you can't change that order. Parentheses are not valid inside tags. So split a long condition into nested if blocks rather than trying to group it.

Filters

Filters chain from left to right and take arguments after a colon. A few details from the reference:

  • Prices are whole numbers. Price fields come out in the currency's subunit, so a price of 1000 prints as 10.00 in the store's currency format once it goes through money.
  • image_url needs a size. Give it a width or a height. An image is never made larger than the original.
  • Filters have a home. Under the strict parser they only work in output tags, assign and echo. You can't put one inside a render argument. Assign the result to a variable first.

Snippets: why render replaced include

A snippet is a reusable file in snippets/. Merchants can't see snippets in the theme editor, so they suit product cards, icons and price blocks.

Call one with render:

{% render 'product-card', product: item, show_price: true %}
{% render 'product-card' for collection.products as product %}

The first line passes named values. The second renders the snippet once per item, and as product names the current item inside the snippet. The render reference also documents with for passing a single object.

The Liquid render tag reference page on shopify.dev
The render reference documents the for, as and with parameters for passing data into a snippet, shopify.dev

Scope is the point. A snippet can't read variables you created outside it. It can read global objects and objects that are directly available where it's rendered, such as section inside a section. Variables it creates stay inside it.

Two panels comparing render, where a snippet only sees what is passed, with include, where a snippet shares the caller's variables
With render, a snippet sees what you pass, global objects such as settings, and objects available where it renders, such as section. Original diagram, Ecompanda

The older include tag shared one scope with the page. The include reference marks it deprecated because the way it handles variables "reduces performance and makes code harder to both read and maintain". If your theme still uses it, replace each call and pass the variables the snippet needs.

Document your snippets with LiquidDoc

Shopify announced LiquidDoc on 21 May 2025. A {% doc %} block at the top of a snippet or block file is read by code editors and Theme Check. A missing parameter then shows up as a warning instead of a silent bug. Parameters are written @param {type} name - description, with square brackets around optional ones. Here is snippets/price.liquid:

{% doc %}
  Prints the price of one variant, with a struck-through compare-at
  price when the variant is on sale.

  @param {object} variant - The variant to price
  @param {boolean} [show_compare_at] - Set to false to hide the compare-at price

  @example
  {% render 'price', variant: product.selected_or_first_available_variant %}
{% enddoc %}

{%- liquid
  assign on_sale = false
  if variant.compare_at_price and variant.compare_at_price > variant.price
    assign on_sale = true
  endif
-%}

<div class="price{% if on_sale %} price--on-sale{% endif %}">
  <span class="price__current">{{ variant.price | money }}</span>
  {%- if on_sale and show_compare_at != false -%}
    <s class="price__compare">{{ variant.compare_at_price | money }}</s>
  {%- endif -%}
</div>
The LiquidDoc page on shopify.dev showing the basic doc tag structure
LiquidDoc sits in a doc tag at the top of a snippet or block file, with one @param line per input, shopify.dev

Why price the variant and not the product? Product price fields are the lowest across all variants. On a product page you want the selected one. And compare_at_price is empty when none is set, so the snippet checks it exists before comparing.

Sections and blocks in Liquid

A section file holds markup, a {% schema %} with the settings merchants edit, and presets that let it be added in the theme editor. Inside it, section.settings reads those settings and section.id identifies the instance. Our sections and blocks guide covers the editor side.

Theme blocks live in blocks/ and can be reused across sections. The section marks where they go with content_for 'blocks' and accepts them with @theme in its schema. This is sections/feature-list.liquid:

<section class="feature-list" style="--columns: {{ section.settings.columns }}">
  {%- if section.settings.heading != blank -%}
    <h2>{{ section.settings.heading | escape }}</h2>
  {%- endif -%}
  <div class="feature-list__items">
    {% content_for 'blocks' %}
  </div>
</section>

{% schema %}
{
  "name": "Feature list",
  "settings": [
    { "type": "text", "id": "heading", "label": "Heading", "default": "Why shop with us" },
    { "type": "range", "id": "columns", "label": "Columns", "min": 1, "max": 4, "step": 1, "default": 3 }
  ],
  "blocks": [{ "type": "@theme" }],
  "presets": [{ "name": "Feature list" }]
}
{% endschema %}

And the block it accepts, blocks/feature.liquid:

<div class="feature" {{ block.shopify_attributes }}>
  <h3>{{ block.settings.title | escape }}</h3>
  <p>{{ block.settings.text | escape }}</p>
</div>

{% schema %}
{
  "name": "Feature",
  "settings": [
    { "type": "text", "id": "title", "label": "Title", "default": "Free returns" },
    { "type": "textarea", "id": "text", "label": "Text" }
  ],
  "presets": [{ "name": "Feature" }]
}
{% endschema %}

block.shopify_attributes prints the data attributes the theme editor uses to find a block.

Section blocks are the older style. They're declared in the section's own schema and looped with section.blocks, with a limit of 50 blocks per section. Branch on block.type, never on block.id. The section schema page warns that block IDs are generated and can change.

{%- for block in section.blocks -%}
  {%- case block.type -%}
    {%- when 'feature' -%}
      <div class="feature" {{ block.shopify_attributes }}>
        <h3>{{ block.settings.title | escape }}</h3>
      </div>
  {%- endcase -%}
{%- endfor -%}

A static block is placed in code instead of by the merchant: {% content_for 'block', type: 'feature', id: 'trust-badge' %}. See the content_for reference.

Patterns you will use every week

Metafield output

Metafields are read with resource.metafields.namespace.key. You can't create them in Liquid, only in the admin or through an app. Check for a value with blank, then print:

{%- assign ingredients = product.metafields.custom.ingredients -%}
{%- if ingredients != blank -%}
  <h2>Ingredients</h2>
  {{ ingredients | metafield_tag }}
{%- endif -%}

{%- assign note = product.metafields.custom.care_note.value -%}
{%- if note != blank -%}
  <p>{{ note | escape }}</p>
{%- endif -%}

metafield_tag picks an HTML element by metafield type, but it doesn't support most list types yet. .value gives you the raw value. If a key is named size, first or last, use brackets (namespace["size"]), because those are filter names too. More in our metafields guide.

Loops with limits

A for loop runs at most 50 times. Past that you need paginate. Use limit to stop early, offset to skip items and else for an empty list.

The for tag reference on shopify.dev stating the 50 iteration maximum
A for loop stops after 50 iterations, so longer lists need paginate, shopify.dev

Inside a loop, forloop tells you where you are: first, last, index (from 1), index0, length, rindex and parentloop. This one numbers items and loads the first two images eagerly, since shoppers see them without scrolling:

<ul class="product-strip">
  {%- for item in collection.products limit: 8 -%}
    {%- liquid
      assign loading = 'lazy'
      if forloop.index <= 2
        assign loading = 'eager'
      endif
    -%}
    <li>
      <span>{{ forloop.index }} of {{ forloop.length }}</span>
      <a href="{{ item.url }}">{{ item.title | escape }}</a>
      {%- if item.featured_image -%}
        {{ item.featured_image | image_url: width: 600 | image_tag: loading: loading, widths: '300, 450, 600' }}
      {%- endif -%}
    </li>
  {%- else -%}
    <li>No products in this collection yet.</li>
  {%- endfor -%}
</ul>

image_tag adds width, height and a srcset for you. If you don't set preload, it also lazy-loads images in sections further down the page.

For longer lists, the paginate tag takes between 1 and 250 items per page and stops at the 25,000th item:

{% paginate collection.products by 24 %}
  {% for product in collection.products %}
    {% render 'product-card', product: product %}
  {% endfor %}
  {{ paginate | default_pagination }}
{% endpaginate %}

Array filters: find, has and reject

Shopify added find, find_index, has and reject on 11 February 2025. They take a property name and a value, and they replace a lot of small loops:

{%- assign large = product.variants | find: 'title', 'Large' -%}
{%- if large and large.available -%}
  <p>Large is in stock.</p>
{%- endif -%}

{%- assign without_gift_cards = collection.products | reject: 'type', 'Gift Card' -%}

What is new, and what is going away

DateChangeStatus
11 Feb 2025find, find_index, has, reject array filtersLive
21 May 2025LiquidDoc with the doc tagLive
13 Jan 2026Stricter Liquid parsing for all themesEnforced
Not datedinclude tagDeprecated, use render
21 Jul 2026block and partial tagsAnnounced as a developer preview, now in the reference

Stricter parsing. On 13 January 2026 Shopify started enforcing a stricter parser on themes. Code that doesn't meet it is rewritten automatically. The migration guide lists the usual failures:

  • A filter inside a render argument. Assign it to a variable first.
  • A condition such as settings.x or settings.y as a render argument. Wrap the render in an if.
  • with combined with key-value pairs, or a colon right after with.
  • or and and inside assign or case. Logical operators belong in if.
  • &&, || or parentheses in a condition. Write and and or, with no grouping.
The migration guide for Liquid's strictest parser on shopify.dev
The migration guide lists each code pattern the stricter parser rejects, with a fix for each, shopify.dev

The fix for the first case looks like this:

{% assign alt_text = product.featured_image.alt | escape %}
{% render 'image', image: product.featured_image, alt: alt_text %}

The block and partial tags. On 21 July 2026 Shopify announced a developer preview with two new tags. {% block %} renders a theme block straight from a Liquid template, much like render does for a snippet. {% partial %} marks a named region of server-rendered HTML that JavaScript can refresh without a full page reload. Both tags now have pages in the main Liquid reference. But we did not find a changelog post that announces general availability. Shopify's announcement says to try them on a development store created with the Liquid July '26 developer preview, so do that before you build a live theme on them. Shopify says existing themes keep working with sections, theme settings and JSON templates.

Performance habits that pay off

Shopify's performance guidance names the usual causes of slow Liquid: loops that grow with the catalogue, nested loops, metafield reads inside loops, and looping over more variants or products than the page shows. In practice:

  1. Avoid deeply nested loops. Each level multiplies the work as the catalogue grows.
  2. Read metafields once, outside the loop. Use theme settings for data that never changes.
  3. Don't loop over every variant when the first view only needs a few.
  4. Limit what you fetch. A limit on collection.products helps. Other arrays need paginate.
  5. Assign repeated values before the loop, so a filter runs once instead of once per item.

The guide also suggests section.index and section.location to treat sections above the fold differently. To find slow lines, the Shopify Theme Inspector for Chrome shows Liquid render time as a flame graph. More habits are in our theme performance guide.

Debugging and Theme Check

Theme Check is Shopify's linter for the Liquid and JSON in a theme. It runs through Shopify CLI and comes built into the Shopify Liquid extension for Visual Studio Code.

shopify theme check
shopify theme check --auto-correct
The Theme Check checks reference table on shopify.dev
Every Theme Check check has a severity, error or warning, and its own page explaining the fix, shopify.dev

Checks worth knowing, from the checks reference:

CheckWhat it catches
UnknownFilter, UndefinedObjectTypos in filters and objects
UnusedAssignVariables assigned and never used
DeprecatedTaginclude and other deprecated tags
MissingRenderSnippetArgumentsA required LiquidDoc parameter was not passed
ImgWidthAndHeightimg tags without width and height

When something breaks, we work through it in this order:

  1. Run Theme Check. Most "my section vanished" bugs are syntax errors it names for you.
  2. Print the value: <pre>{{ product.tags | json }}</pre> shows what Liquid really holds. Delete it before you publish.
  3. Comment out code with {% comment %} or {% # %} until the faulty line shows itself.
  4. Work on a duplicate of the live theme, never the published one.

Hiring a Shopify Liquid developer: what to ask

Plenty of people can edit Liquid. Fewer leave a theme cleaner than they found it. Before you hand over a theme, ask:

  • Will you work on a duplicate theme or a development store, and never on the live one?
  • Will the code pass shopify theme check with no errors?
  • Do you use render with LiquidDoc for snippets, and no include?
  • How do you keep loops small, and do you read metafields outside them?
  • Will the code parse under the stricter parser without being rewritten?

Clear answers to those tell you more than a portfolio. If you'd rather have someone else do it, we build and fix Shopify themes, from a single section to a custom theme. Tell us what you want to change and we'll say how we'd approach it.

Frequently asked questions

What is Shopify Liquid used for?

It builds Shopify themes. Liquid reads store data such as products, collections, the cart and theme settings, and prints it into HTML. Every Online Store theme is built from Liquid files.

Is Liquid a programming language?

It's a template language. It can branch, loop and format data, but its job is to read what Shopify provides and print HTML. It can't even create metafields. Anything that must store data or talk to another system belongs in an app or in JavaScript on the page.

What is the difference between {{ }} and {% %}?

Double curly braces print a value. Curly brace percentage delimiters run logic, such as a condition or a loop, and the tag text itself is not printed. Inside a {% liquid %} tag, use echo to print.

Is Liquid only used by Shopify?

No. Shopify created it and publishes it as open source, and other software projects use it too. But Shopify's theme version adds its own tags, filters and objects, so code from another platform won't always run in a theme.

Should I use include or render?

Use render. Shopify deprecated include because its shared variables reduce performance and make code harder to read. render isolates the snippet, so you pass in what it needs by name. Theme Check flags include.

Why does my if statement pass when the field is empty?

Because an empty string is truthy in Liquid. Only nil and false are falsy. Compare with blank, as in {% if section.settings.heading != blank %}. The same goes for 0 and empty arrays.

What changed with the January 2026 parser update?

From 13 January 2026 Shopify enforces stricter parsing on themes, and code that doesn't meet it is rewritten automatically. The usual causes are filters or conditions inside render arguments, and and or or inside assign or case. Run Theme Check and read the migration guide.

Can I use the new block and partial tags in a live store?

Test first. Shopify's announcement says to try them on a development store created with the Liquid July '26 developer preview. Shopify announced them as a developer preview on 21 July 2026. They now appear in the Liquid reference, but we found no announcement of general availability. Existing themes keep working with sections and JSON templates, so there is no need to migrate.

Sources

The main pages this guide rests on. Read the current version before you rely on a detail.

← All guidesMore on shopify development

Related content

More on shopify development

All guides

Shopify development

Shopify Theme Customization: A Safe Workflow and Review Checklist

To customize a Shopify theme safely, use the theme editor first, do code work on a copy, run Theme Check and a review checklist, then publish with the old theme kept for rollback. This guide covers each step and what to do when a theme won't stretch far enough.

Shopify development

How to Add Custom CSS to Shopify, Step by Step

To add custom CSS to Shopify, go to Online Store, Edit theme, Theme settings, Custom CSS, paste your code and save. One section has its own 500-character box, and bigger changes belong in your theme code.

Free newsletter

Enjoying this guide? Get one tactic like it every week.

Short notes on Shopify, AI search and conversion, taken from our own work. Unsubscribe in one click.

Let’s make your store your best salesperson.

Tell us where your brand is headed in the next twelve months and we will show you how your store can get it there. Book a 15 minute call or send us a message, and we reply within one business day.

Replies within one business day