Liquid reference
Objects, tags and filters available in sections, snippets and the layout.
Themes use Liquid, the same template language Shopify uses. Most Shopify theme code works with little or no change. Liquid here is sandboxed: it can't run JavaScript on the server, and loops and rendering time are limited.
Global objects#
| Object | Available on | Highlights |
|---|---|---|
shop | every page | name, email, phone, description, currency, url, domain, logo, address, policies |
settings | every page | Theme settings, e.g. settings.color_accent (list) |
routes | every page | root_url, cart_url, cart_add_url, account_url, account_login_url, search_url, collections_url, all_products_collection_url, predictive_search_url |
request | every page | path, host, page_type, design_mode (true inside the visual editor) |
template | every page | template.name (e.g. product), template.suffix |
cart | every page | item_count, total_price, items (title, quantity, final_line_price, image, url, variant_title…), note |
customer | every page | The logged-in customer or nil |
collections | every page | collections['handle'] or collections.all → title, description, image, url, products, all_products_count |
all_products | every page | all_products['handle'] → a product |
pages | every page | pages['handle'] → title, content, url |
linklists | every page | linklists['main-menu'].links → title, url, active, links (nested) |
product | product page | see below |
collection | collection page | products (paginated), sort_by, sort_options, all_products_count |
page | content pages | title, content, handle |
page_title, page_description, canonical_url | every page | SEO values for the layout <head> |
product#
id, title, handle, url, description, vendor, type, tags, price, price_min, price_max, price_varies, compare_at_price, available, featured_image, images, media, options, options_with_values, variants, has_only_default_variant, selected_or_first_available_variant, first_available_variant, seo_title, seo_description, created_at.
Each variant has id, title, price, compare_at_price, available, sku, inventory_quantity, option1…3, image.
{{ product.price | money }}.Tags#
| Tag | Example | |
|---|---|---|
if / elsif / else / unless | {% if product.available %}…{% else %}Sold out{% endif %} | |
case / when | {% case block.type %}{% when 'heading' %}…{% endcase %} | |
for (with limit, offset, reversed, forloop), break, continue, cycle, tablerow | {% for p in collection.products limit: 4 %}{{ forloop.index }}{% endfor %} | |
assign, capture, increment, decrement | `{% assign sale = product.compare_at_price \ | minus: product.price %}` |
render | {% render 'product-card', product: p, show_vendor: true %} | |
section / sections | {% sections 'header-group' %} (layout only) | |
form | {% form 'product', product %}…{% endform %}, also 'contact', 'customer_login', 'create_customer', 'customer_address' | |
paginate | {% paginate collection.products by 24 %}…{% render 'pagination', paginate: paginate %}{% endpaginate %} | |
style | {% style %}.x{color:{{ settings.color_accent }}}{% endstyle %} | |
liquid, echo | Several statements in one tag, one per line: {% liquid ⏎ assign a = 1 ⏎ echo a ⏎ %} | |
raw, comment | Output Liquid literally / leave notes |
Whitespace control ({%- / -%}) is supported.
Built-in snippets#
| Snippet | Parameters |
|---|---|
product-card | product, plus optional show_vendor, quick_add |
product-card-placeholder | (none). Shown when a collection is empty |
price | product or variant |
pagination | paginate |
product-main | product, section, compact. The full product form used by main-product and featured-product |
icon | name (e.g. cart, search, truck, shield, return) |
Filters#
Money: money, money_with_currency, money_without_currency, money_without_trailing_zeros
Images and assets: image_url: width: 800 (also height, crop), img_url, image_tag, placeholder_image, placeholder_svg_tag, asset_url, file_url, stylesheet_tag, script_tag
Text: escape, escape_once, upcase, downcase, capitalize, append, prepend, replace, replace_first, remove, remove_first, strip, lstrip, rstrip, strip_html, strip_newlines, newline_to_br, truncate, truncatewords, split, slice, pluralize, handleize, camelize, highlight, url_encode, url_escape, url_param_escape, link_to, within, t
Math: plus, minus, times, divided_by, modulo, abs, round, ceil, floor, at_least, at_most
Arrays: join, first, last, size, reverse, sort, sort_natural, uniq, compact, map, where, concat, sum
Other: default, json, date: "%d %b %Y", weight_with_unit, color_to_rgb, color_modify, font_family, md5, sha256, base64_encode, structured_data
Example: a product grid#
{%- assign c = collections[section.settings.collection] | default: collections.all -%}
<div class="section-pad"><div class="container">
<h2 class="h-lg">{{ c.title | escape }}</h2>
<div class="product-grid" style="--cols: 4; --cols-m: 2">
{%- for p in c.products limit: 8 -%}
{% render 'product-card', product: p %}
{%- else -%}
{%- for i in (1..4) -%}{% render 'product-card-placeholder' %}{%- endfor -%}
{%- endfor -%}
</div>
</div></div>