Show Menu
Cheatography

Shopify Liquid Cheat Sheet by

A comprehensive Shopify Liquid cheat sheet covering tags, filters, variables, and best practices for theme development. Includes control flow statements, string manipulation, object references, and template includes.

Best Practices & Tips

Use {% render %} for isolated scope
Use {% comment %} for inline notes
Avoid nested if statements
Use {% case %} for many options
Minimize use of filters in loops
Use snippets for reusable code
Separate concerns per file
Test variables with unless nil
Limit array iterations
Avoid complex condit­ional logic
Use forloop variables wisely
Check for nil before accessing

Common Objects

product
Current product object
collection
Current collection object
article
Current blog article
shop
Shop/theme settings
page
Current page object
customer
Logged-in customer data
cart
Shopping cart object
settings
Theme config­uration
request
Request inform­ation (URL, etc)
Access global Liquid objects like product, collec­tion, shop, and customer. These contain data about the current context. Properties are accessed using dot notation (e.g., produc­t.t­itle).

Tags

Condit­ional statement
{% if condition %}
...
{% endif %}
Unless condition (opposite of if)
{% unless condition %}
...
{% endunless %}
Switch­/Case statement
{% case variable %}
...
{% when value %}
...
{% endcase %}
Loop (for each item)
{% for item in collection %}
...
{% endfor %}
Liquid tags are used to create dynamic content and control flow in Shopify theme templates. They allow you to add condit­ional logic, loops, and variable assign­ments to your template code. Tags are enclosed in {% %} brackets.
 

Variable Assignment

Assign Variable
{% assign var = 'value' %}
Assign with Filter
{%​ assign var = var | filter %}
Capture Output
{%​ capture var %}
content
{%​ endcapture %}
Increment Counter
{%​ increment var %}
Decrement Counter
{%​ decrement var %}
Create variables using assign, capture output in variables, or use increm­ent­/de­crement for counters. Variables are scoped to the template and can be reused throug­hout.

Variable Output

{{ variable }}
Output variable
{{ 'text' }}
Output text string
{{ 5 }}
Output number
{{ produc­t.title }}
Access object property
{{ array[0] }}
Access array element by index
{{ 'text' | filter }}
Apply single filter to value
{{ var1 | filter1 | filter2 }}
Chain multiple filters
Output variables, strings, numbers, and access object properties and array elements using dot notation or bracket notation. Apply filters to transform values.

Template Tags

Include Snippet
{%​ include 'snipp­et-­name' %}
Include with Variable
{%​ include 'snippet' with product %}
Render Snippet (Isolated)
{%​ render 'snipp­et-­name' %}
Comment Block
{%​ comment %}...{%​ endcomment %}
Raw/Li­teral Block
{%​ raw %}...{%​ endraw %}
Include snippets, pass variables to includes, or use render for isolated scope. Use comment tags for multi-line comments or raw tags to prevent Liquid proces­sing.

Advanced Filters

base64­_encode
Encode to base64
base64­_decode
Decode from base64
url_encode
Encode URL parameter
url_decode
Decode URL parameter
escape
Escape HTML characters
escape­_once
Escape only unescaped HTML
json
Output as JSON string
md5
MD5 hash
sha1
SHA1 hash
compact
Remove nil/null values
default: 'fallback'
Fallback if nil/empty
where_exp: 'condi­tion'
Advanced array filtering
Encode­/decode base64 and URLs, escape HTML, generate hashes (MD5, SHA1), or output JSON. Use compact to remove nil values and where_exp for complex array filtering.
 

String Filters

upcase
Convert to UPPERCASE
downcase
Convert to lowercase
capitalize
Capitalize first letter
size
Get string­/array length
split: '|'
Split string by delimiter
join: ', '
Join array with separator
strip
Remove whitespace
append: 'text'
Add text to end
prepend: 'text'
Add text to start
remove: 'text'
Remove substring
replace: 'a','b'
Replace 'a' with 'b'
Transform strings with upcase, downcase, capita­lize, split, join, strip, and replace. Use size to get length. These filters are chainable for multiple transf­orm­ations.

Math Filters

plus: n
Add n to number
minus: n
Subtract n from number
times: n
Multiply number by n
divided_by: n
Divide number by n
modulo: n
Get remainder of division
round: n
Round to n decimals
ceil
Round up to nearest integer
floor
Round down to nearest integer
abs
Absolute value
Perform mathem­atical operations on numbers with plus, minus, times, divide­d_by, and modulo. Use round, ceil, and floor for rounding, or abs for absolute value.

Array Filters

sort
Sort array alphab­eti­cally
reverse
Reverse array order
first
Get first element
last
Get last element
map: 'property'
Map/ex­tract property from objects
where: 'key',­'val'
Filter array by condition
uniq
Remove duplicate values
concat: array
Concat­ena­te/join two arrays
size
Get array length
Manipulate arrays with sort, reverse, first, last, and map. Filter arrays with where, remove duplicates with uniq, or join arrays with concat. Size returns array length.
               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet
          Python Cheat Sheet
          Drupal 6 Theme Variables Cheat Sheet