Shopify Liquid Templating
Before writing code
Fetch live docs:
- Fetch
https://shopify.dev/docs/api/liquid for Liquid reference
- Web-search
site:shopify.dev liquid objects for available objects
- Web-search
site:shopify.dev liquid filters for available filters
What Is Liquid
Liquid is Shopify's template language:
- Ruby-based, open-source (created by Shopify)
- Renders on Shopify's servers — no client-side execution
- Three building blocks: objects, tags, filters
- Shopify extends standard Liquid with commerce-specific objects and filters
Objects
Access data with double curly braces:
{{ product.title }} — product name
{{ product.price | money }} — formatted price
{{ cart.item_count }} — number of items in cart
Key Global Objects
| Object |
Description |
product |
Current product (on product pages) |
collection |
Current collection |
cart |
Shopping cart |
customer |
Logged-in customer (nil if guest) |
shop |
Store settings |
request |
Current request (locale, page type) |
content_for_header |
Required scripts/meta (must be in layout) |
content_for_layout |
Template content (must be in layout) |
all_products |
Access any product by handle |
collections |
All collections |
linklists |
Navigation menus |
pages |
CMS pages |
settings |
Theme settings |
Tags
Control flow and logic:
Control Flow
{% if product.available %}
<span>In stock</span>
{% elsif product.variants.size > 0 %}
<span>Limited</span>
{% else %}
<span>Sold out</span>
{% endif %}
{% unless customer %}
<a href="/account/login">Log in</a>
{% endunless %}
{% case product.type %}
{% when 'Shirt' %}
<p>Clothing</p>
{% when 'Mug' %}
<p>Accessories</p>
{% endcase %}
Iteration
{% for product in collection.products %}
<h2>{{ product.title }}</h2>
{% endfor %}
{% for item in cart.items limit:5 offset:2 %}
{{ item.title }}
{% endfor %}
{% paginate collection.products by 12 %}
{% for product in collection.products %}
{{ product.title }}
{% endfor %}
{{ paginate | default_pagination }}
{% endpaginate %}
Variable
{% assign greeting = 'Hello' %}
{% capture full_greeting %}{{ greeting }}, {{ customer.first_name }}!{% endcapture %}
Filters
Transform output:
- String:
upcase, downcase, strip, truncate, replace, split, url_encode
- Number:
plus, minus, times, divided_by, round, ceil, floor
- Money:
money, money_with_currency, money_without_trailing_zeros
- Date:
date: '%B %d, %Y'
- Array:
first, last, size, sort, map, where, join, uniq
- HTML:
img_tag, script_tag, stylesheet_tag
- URL:
asset_url, img_url, file_url, shopify_asset_url
- Media:
image_url, image_tag (modern replacements for img_url/img_tag)
Section Schema
Sections define their own settings in a {% schema %} tag:
{% schema %}
{
"name": "Featured Product",
"settings": [
{
"type": "product",
"id": "product",
"label": "Product"
},
{
"type": "color",
"id": "background_color",
"label": "Background color",
"default": "#ffffff"
}
],
"blocks": [
{
"type": "text",
"name": "Text block",
"settings": [
{
"type": "richtext",
"id": "content",
"label": "Content"
}
]
}
],
"presets": [
{
"name": "Featured Product"
}
]
}
{% endschema %}
JSON Templates (Online Store 2.0)
Templates are JSON files that reference sections:
{
"sections": {
"main": {
"type": "main-product",
"settings": {}
},
"recommendations": {
"type": "product-recommendations",
"settings": {
"heading": "You may also like"
}
}
},
"order": ["main", "recommendations"]
}
Deprecated — Do NOT Reference
- Timber — deprecated starter theme; use Dawn instead
- Section-only themes without JSON templates (pre-Online Store 2.0)
Best Practices
- Use
image_url and image_tag instead of deprecated img_url / img_tag
- Use JSON templates for all page types (Online Store 2.0)
- Keep logic minimal — Liquid is a template language, not a programming language
- Use
{% comment %} for documentation, not HTML comments (which are sent to the browser)
- Use snippets (
{% render 'snippet-name' %}) for reusable code — {% include %} is deprecated
- Use
{% render %} over {% include %} — render creates an isolated scope
- Apply
| escape filter to user-generated content to prevent XSS
- Use section settings for merchant-configurable values instead of hardcoding
Fetch the Shopify Liquid reference for exact object properties, available filters, and section schema options before implementing.
1---2name: shopify-liquid3description: Write Shopify Liquid templates — objects, tags, filters, global objects, section schema, Online Store 2.0 JSON templates, and Liquid best practices. Use when customizing Shopify theme templates.4---56# Shopify Liquid Templating78## Before writing code910**Fetch live docs**:111. Fetch `https://shopify.dev/docs/api/liquid` for Liquid reference122. Web-search `site:shopify.dev liquid objects` for available objects133. Web-search `site:shopify.dev liquid filters` for available filters1415## What Is Liquid1617Liquid is Shopify's template language:18- Ruby-based, open-source (created by Shopify)19- Renders on Shopify's servers — no client-side execution20- Three building blocks: **objects**, **tags**, **filters**21- Shopify extends standard Liquid with commerce-specific objects and filters2223## Objects2425Access data with double curly braces:26- `{{ product.title }}` — product name27- `{{ product.price | money }}` — formatted price28- `{{ cart.item_count }}` — number of items in cart2930### Key Global Objects3132| Object | Description |33|--------|-------------|34| `product` | Current product (on product pages) |35| `collection` | Current collection |36| `cart` | Shopping cart |37| `customer` | Logged-in customer (nil if guest) |38| `shop` | Store settings |39| `request` | Current request (locale, page type) |40| `content_for_header` | Required scripts/meta (must be in layout) |41| `content_for_layout` | Template content (must be in layout) |42| `all_products` | Access any product by handle |43| `collections` | All collections |44| `linklists` | Navigation menus |45| `pages` | CMS pages |46| `settings` | Theme settings |4748## Tags4950Control flow and logic:5152### Control Flow53```liquid54{% if product.available %}55 <span>In stock</span>56{% elsif product.variants.size > 0 %}57 <span>Limited</span>58{% else %}59 <span>Sold out</span>60{% endif %}6162{% unless customer %}63 <a href="/account/login">Log in</a>64{% endunless %}6566{% case product.type %}67 {% when 'Shirt' %}68 <p>Clothing</p>69 {% when 'Mug' %}70 <p>Accessories</p>71{% endcase %}72```7374### Iteration75```liquid76{% for product in collection.products %}77 <h2>{{ product.title }}</h2>78{% endfor %}7980{% for item in cart.items limit:5 offset:2 %}81 {{ item.title }}82{% endfor %}8384{% paginate collection.products by 12 %}85 {% for product in collection.products %}86 {{ product.title }}87 {% endfor %}88 {{ paginate | default_pagination }}89{% endpaginate %}90```9192### Variable93```liquid94{% assign greeting = 'Hello' %}95{% capture full_greeting %}{{ greeting }}, {{ customer.first_name }}!{% endcapture %}96```9798## Filters99100Transform output:101- **String**: `upcase`, `downcase`, `strip`, `truncate`, `replace`, `split`, `url_encode`102- **Number**: `plus`, `minus`, `times`, `divided_by`, `round`, `ceil`, `floor`103- **Money**: `money`, `money_with_currency`, `money_without_trailing_zeros`104- **Date**: `date: '%B %d, %Y'`105- **Array**: `first`, `last`, `size`, `sort`, `map`, `where`, `join`, `uniq`106- **HTML**: `img_tag`, `script_tag`, `stylesheet_tag`107- **URL**: `asset_url`, `img_url`, `file_url`, `shopify_asset_url`108- **Media**: `image_url`, `image_tag` (modern replacements for `img_url`/`img_tag`)109110## Section Schema111112Sections define their own settings in a `{% schema %}` tag:113114```liquid115{% schema %}116{117 "name": "Featured Product",118 "settings": [119 {120 "type": "product",121 "id": "product",122 "label": "Product"123 },124 {125 "type": "color",126 "id": "background_color",127 "label": "Background color",128 "default": "#ffffff"129 }130 ],131 "blocks": [132 {133 "type": "text",134 "name": "Text block",135 "settings": [136 {137 "type": "richtext",138 "id": "content",139 "label": "Content"140 }141 ]142 }143 ],144 "presets": [145 {146 "name": "Featured Product"147 }148 ]149}150{% endschema %}151```152153## JSON Templates (Online Store 2.0)154155Templates are JSON files that reference sections:156157```json158{159 "sections": {160 "main": {161 "type": "main-product",162 "settings": {}163 },164 "recommendations": {165 "type": "product-recommendations",166 "settings": {167 "heading": "You may also like"168 }169 }170 },171 "order": ["main", "recommendations"]172}173```174175## Deprecated — Do NOT Reference176177- **Timber** — deprecated starter theme; use Dawn instead178- Section-only themes without JSON templates (pre-Online Store 2.0)179180## Best Practices181182- Use `image_url` and `image_tag` instead of deprecated `img_url` / `img_tag`183- Use JSON templates for all page types (Online Store 2.0)184- Keep logic minimal — Liquid is a template language, not a programming language185- Use `{% comment %}` for documentation, not HTML comments (which are sent to the browser)186- Use snippets (`{% render 'snippet-name' %}`) for reusable code — `{% include %}` is deprecated187- Use `{% render %}` over `{% include %}` — render creates an isolated scope188- Apply `| escape` filter to user-generated content to prevent XSS189- Use section settings for merchant-configurable values instead of hardcoding190191Fetch the Shopify Liquid reference for exact object properties, available filters, and section schema options before implementing.