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.
|
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 conditional logic
|
|
Use forloop variables wisely
|
|
Check for nil before accessing
|
|
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 configuration
|
|
request
|
Request information (URL, etc)
|
|
Conditional statement
{% if condition %}
|
|
Unless condition (opposite of if)
{% unless condition %}
|
|
Switch/Case statement
{% case variable %}
|
|
Loop (for each item)
{% for item in collection %}
|
|
Assign Variable
{% assign var = 'value' %}
|
|
Assign with Filter
{% assign var = var | filter %}
|
|
Capture Output
{% capture var %}
|
|
Increment Counter
{% increment var %}
|
|
Decrement Counter
{% decrement var %}
|
|
{{ variable }}
|
Output variable
|
|
{{ 'text' }}
|
Output text string
|
|
{{ 5 }}
|
Output number
|
|
{{ product.title }}
|
Access object property
|
|
{{ array[0] }}
|
Access array element by index
|
|
{{ 'text' | filter }}
|
Apply single filter to value
|
|
{{ var1 | filter1 | filter2 }}
|
Chain multiple filters
|
|
Include Snippet
{% include 'snippet-name' %}
|
|
Include with Variable
{% include 'snippet' with product %}
|
|
Render Snippet (Isolated)
{% render 'snippet-name' %}
|
|
Comment Block
{% comment %}...{% endcomment %}
|
|
Raw/Literal Block
{% raw %}...{% endraw %}
|
|
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: 'condition'
|
Advanced array filtering
|
|
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'
|
|
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
|
|
sort
|
Sort array alphabetically
|
|
reverse
|
Reverse array order
|
|
first
|
Get first element
|
|
last
|
Get last element
|
|
map: 'property'
|
Map/extract property from objects
|
|
where: 'key','val'
|
Filter array by condition
|
|
uniq
|
Remove duplicate values
|
|
concat: array
|
Concatenate/join two arrays
|
|
size
|
Get array length
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.