Skip to content
Resources

Shopify Liquid cheat sheet: objects, tags and filters with examples

Liquid is the template language behind every Shopify theme. Whether you want to show a “Sale” badge, change how prices are displayed or build a custom section, sooner or later you need to edit some Liquid code. The problem is that the official reference is huge, and when you just need the right syntax for one filter, you don’t want to read 200 pages.

In this post, I put together a practical Shopify Liquid cheat sheet: the objects, tags and filters you use the most, each with a short example you can copy into your theme. It works with Online Store 2.0 themes like Dawn and Horizon.

Before you edit any theme file, duplicate your theme in Online Store > Themes (click … > Duplicate) so you can always roll back.

shopify-liquid-objects-tags-filters

Liquid syntax basics

Liquid has only two kinds of delimiters:

{{ product.title }}          <!-- output: prints a value -->
{% if product.available %}   <!-- tag: logic, no output -->
  In stock
{% endif %}
{{ product.title | upcase }} <!-- filter: changes the output -->
{%- if true -%} ... {%- endif -%}   <!-- the dash trims whitespace -->

Shopify Liquid objects cheat sheet

Objects hold the store data. These are the ones you will use most often:

{{ shop.name }}                     store name
{{ shop.url }}                      store URL
{{ product.title }}                 product name
{{ product.price | money }}         price of the selected/first variant
{{ product.compare_at_price }}      original price (for sales)
{{ product.available }}             true if at least one variant can be sold
{{ product.url }}                   product URL
{{ product.featured_image }}        main image
{{ product.selected_or_first_available_variant.sku }}
{{ product.metafields.custom.material }}   a metafield value
{{ collection.title }}              collection name
{{ collection.products_count }}
{{ cart.item_count }}               number of items in the cart
{{ cart.total_price | money }}
{{ customer.first_name }}           logged-in customer (nil for guests)
{{ request.page_type }}             product, collection, index, cart...
{{ routes.cart_url }}               /cart (works with every locale)
{{ settings.colors_accent_1 }}      a theme setting
{{ section.settings.heading }}      a setting of the current section
{{ block.settings.text }}           a setting of the current block

Liquid tags cheat sheet

Conditions

{% if product.available and product.price < 5000 %}
  Under $50
{% elsif product.available %}
  In stock
{% else %}
  Sold out
{% endif %}

{% unless customer %}Log in to see member prices{% endunless %}

{% case product.type %}
  {% when 'T-Shirts' %}Free returns on T-shirts
  {% else %}30-day returns
{% endcase %}

Prices in Liquid are in cents, so 5000 means 50.00.

Loops

{% for product in collection.products limit: 4 %}
  {{ forloop.index }}. {{ product.title }}
{% else %}
  This collection is empty.
{% endfor %}

{% paginate collection.products by 24 %}
  {% for product in collection.products %}...{% endfor %}
  {{ paginate | default_pagination }}
{% endpaginate %}

Variables

{% assign sale = false %}
{% if product.compare_at_price > product.price %}{% assign sale = true %}{% endif %}

{% capture badge %}Save {{ product.compare_at_price | minus: product.price | money }}{% endcapture %}
{{ badge }}

Theme tags

{% render 'product-card', product: product %}      include a snippet
{% render 'price' for collection.products as product %}
{% section 'header' %}                              render a static section
{% form 'product', product %}...{% endform %}      add-to-cart form
{% style %} .badge { color: {{ settings.colors_accent_1 }}; } {% endstyle %}
{% javascript %} console.log('loaded'); {% endjavascript %}
{% comment %} notes for developers {% endcomment %}
{% raw %}{{ this is not parsed }}{% endraw %}
{% schema %} { "name": "My section", "settings": [] } {% endschema %}

Note: {% render %} replaced the old {% include %} tag. Variables from the parent template are not available inside a rendered snippet unless you pass them as parameters. The {% style %} tag outputs a <style data-shopify> element, so color changes in the theme editor are applied live.

Liquid filters cheat sheet

Money filters

{{ product.price | money }}                       $19.00
{{ product.price | money_with_currency }}         $19.00 USD
{{ product.price | money_without_currency }}      19.00
{{ product.price | money_without_trailing_zeros }} $19

Image filters

{{ product.featured_image | image_url: width: 600 }}
{{ product.featured_image | image_url: width: 400, height: 400, crop: 'center' }}
{{ product.featured_image | image_url: width: 800 | image_tag: loading: 'lazy', alt: product.title }}
{{ 'logo.png' | asset_url }}
{{ 'custom.css' | asset_url | stylesheet_tag }}

The old img_url filter is deprecated; use image_url with a width or height instead (up to 5760 px). Don’t lazy-load images that are visible above the fold, like the main product image.

String filters

{{ product.title | upcase }}               CLASSIC T-SHIRT
{{ product.title | handleize }}            classic-t-shirt
{{ product.description | strip_html | truncate: 120 }}
{{ product.title | append: ' - Sale' }}
{{ product.title | replace: 'T-Shirt', 'Tee' }}
{{ product.title | escape }}
{{ customer.first_name | default: 'there' }}
{{ 'products.product.add_to_cart' | t }}   translation from locales/*.json

Array and math filters

{% assign nike = collection.products | where: 'vendor', 'Nike' %}
{% assign in_stock = collection.products | where: 'available' %}
{{ collection.products | map: 'title' | join: ', ' }}
{{ product.tags | size }}
{{ product | json }}
{{ product.price | times: 0.9 | round }}
{{ cart.total_price | divided_by: 100 }}
{{ forloop.index | plus: 1 }}
{{ article.published_at | date: '%B %d, %Y' }}

A complete example: product card with a sale price

Here is how objects, tags and filters work together in a simple product card snippet:

<a href="{{ product.url }}">
  {{ product.featured_image | image_url: width: 600 | image_tag: loading: 'lazy' }}
  <h3>{{ product.title | escape }}</h3>
  {% if product.compare_at_price > product.price %}
    <s>{{ product.compare_at_price | money }}</s>
  {% endif %}
  <span>{{ product.price | money }}</span>
</a>

shopify-liquid-product-card-example

Save it as snippets/product-card.liquid and call it with {% render 'product-card', product: product %} inside a collection loop.

Common errors

“Liquid error: Memory limits exceeded”

A loop or filter processes too much data. Read my fix for the Shopify Liquid error: Memory limits exceeded.

A variable is empty inside a snippet

You used {% render %} without passing the variable. Add it as a parameter, for example {% render 'card', product: product %}.

The price shows 1900 instead of $19.00

You forgot the money filter. Liquid stores prices in cents.

“Liquid syntax error: Unknown tag”

Usually a missing {% endif %} or {% endfor %}, or a tag that doesn’t exist in Shopify Liquid. Shopify’s theme editor shows the line number.

For the full list of objects, tags and filters, see the official Shopify Liquid reference.

Wrapping up

That’s my Shopify Liquid cheat sheet. Remember the three building blocks: objects print data with {{ }}, tags add logic with {% %}, and filters change the output with |. With the examples above you can already customize product cards, prices and sections in most themes. If you want to go further, my tutorial on how to add pages and page templates in Shopify shows where these templates live.

Which Liquid snippet do you use the most? Share it in the comments below.

Written by

Hung Tran

Hung Tran is the main editor of magentip.com, he loves to write about everything related to Magento 2