Conditions code editor
Available for "Custom Sections" widget, contact support to get access to it.
Liquid Template Editor Guide
This guide explains how to write Liquid templates in our editor, including available objects, tags, and best practices.
Template Structure
Liquid templates support three main types of markup:
Output
Display dynamic content using double curly braces:
Control Tags
Control flow using special tags:
Comments
Document your code:
Available Objects
Lines
The lines
array contains information about each item in the cart. Each line item represents a product variant with its quantity and associated data.
Properties
id
Type:
string
Description: Unique identifier for the line item
Example:
"gid://shopify/LineItem/12345"
quantity
Type:
number
Description: Number of items of this variant in the cart
Example:
2
cost
Type:
object
Description: Cost information for this line item
Properties:
totalAmount.amount
(number
): Total cost for this line item including quantity
merchandise
Type:
object
Description: Product variant information
Properties:
id
(string
): Variant identifiertitle
(string
): Product variant titleselectedOptions
(array
): Selected variant optionsname
(string
): Option name (e.g., "Size")value
(string
): Option value (e.g., "Small")
product
(object
): Parent product informationid
(string
): Product identifiervendor
(string
): Product vendor nameproductType
(string
): Product category/type
requiresShipping
(boolean
): Whether the item needs shippingsku
(string
): Stock keeping unit
attributes
Type:
array
Description: Custom attributes attached to the line item
Properties:
key
(string
): Attribute keyvalue
(string
): Attribute value
Usage Example
Cart
The cart
object contains overall information about the shopping cart, including totals and metadata.
Properties
currency
Type:
string
Description: The currency code for the cart
Example:
"USD"
note
Type:
string
Description: Customer notes attached to the cart
Example:
"Please gift wrap"
attributes
Type:
array
Description: Custom attributes for the entire cart
Properties:
key
(string
): Attribute keyvalue
(string
): Attribute value
quantity
Type:
number
Description: Total number of items in the cart
Example:
5
cost
Type:
object
Description: Detailed cost breakdown
Properties:
total
(number
): Final cart total including all costssubtotal
(number
): Sum of line items before tax/shippingtax
(number
): Total tax amountshipping
(number
): Shipping cost
Usage Example
Customer
The customer
object provides information about the current user's status and preferences.
Properties
loggedIn
Type:
boolean
Description: Whether the customer is currently authenticated
Example:
true
acceptsEmailMarketing
Type:
boolean
Description: Customer's email marketing preference
Example:
true
acceptsSmsMarketing
Type:
boolean
Description: Customer's SMS marketing preference
Example:
false
Usage Example
Shipping
The shipping
object contains information about shipping methods and address details.
Properties
state
Type:
string | null
Description: Shipping destination state/province code
Example:
"AL"
country
Type:
string | null
Description: Shipping destination country code
Example:
"US"
selected
Type:
object
Description: Currently selected shipping method
Properties:
label
(string | null
): Display name of the shipping methodtype
('shipping' | 'local' | 'pickup' | 'pickupPoint' | null
): Display type of the shipping method
target
Type:
object | null
Description: Target shipping method information. Only works when the widget is added under Delivery methods.
Properties:
isCurrentSelected
(boolean
): Whether this method is selectedcode
(string
): Shipping method identifiertitle
(string
): Display namecost.amount
(number
): Shipping cost amount
Usage Example
Order
The order
object contains information about the current order being processed.
Properties
payment.selected
Type:
object
Description: Selected payment method information
Properties:
type
('creditCard' | 'deferred' | 'local' | 'manualPayment' | 'offsite' | 'other' | 'paymentOnDelivery' | 'redeemable' | 'wallet' | 'customOnsite' | null
): Payment method type
metafields
Type:
array
Description: Additional custom data attached to the order
Properties:
key
(string
): Metafield identifiervalue
(string
): Metafield valuenamespace
(string
): Grouping namespace. use "checkoutbuilder" to access fields created with "Custom fields" widget.
Usage Example
Filters
The editor supports various filters to transform values. Filters are applied using the pipe character (|
).
String Filters
replace
Replaces all occurrences of a substring
search
(string, required)
replace
(string, required)
upcase
Converts string to uppercase
None
downcase
Converts string to lowercase
None
capitalize
Capitalizes the first character
None
append
Appends a string to the end
suffix
(string, required)
prepend
Prepends a string to the beginning
prefix
(string, required)
strip
Removes whitespace from both ends
None
split
Splits a string into an array
separator
(string, required)
Example
Number Filters
ceil
Rounds up to nearest integer
None
floor
Rounds down to nearest integer
None
round
Rounds to nearest integer
None
divided_by
Divides by a number
divisor
(number, required)
minus
Subtracts a number
subtrahend
(number, required)
plus
Adds a number
addend
(number, required)
times
Multiplies by a number
multiplier
(number, required)
Example
Array Filters
first
Returns the first element
None
last
Returns the last element
None
join
Joins elements with a separator
separator
(string, optional, default: " ")
size
Returns array length
None
Example
Filter Chaining
You can chain multiple filters together. They are applied from left to right.
⚠️ Important Notes
Maximum 3 filters per variable (see complexity rules)
Filters must match the input type they accept
Some filters change the value type (e.g.,
split
converts string to array)Use intermediate variables for complex transformations
Control Flow
Conditional Tags
Available tags:
if
/elsif
/else
/endif
unless
/endunless
Example:
Loops
Available controls:
for
/endfor
break
continue
⚠️ Important Limitations
Maximum 20 iterations per loop
No nested loops allowed
Range loops limited to 20 steps:
(1..20)
Example:
Show/Hide System
Basic Usage
Templates are hidden by default and must be explicitly shown:
📝 Key Rules
First show/hide tag wins
Processing stops at show/hide
Default state is hidden
Template Complexity
Limits
Scoring
Each element adds to complexity:
Loop: +5 points
Condition: +2 points
Assignment: +1 point
Filter: +1 point
Large range loop: +3 extra points
Best Practices
1. Optimize Loops
Pre-calculate values outside loops:
2. Use Early Exits
Exit early when possible:
3. Keep Filters Simple
Avoid long filter chains:
4. Handle Null Values
Always check for null:
5. Document Complex Logic
Use comments for clarity:
6. Optimize Property Usage
Each property access in your template triggers a recalculation when that property changes. To ensure optimal performance:
Only use properties that are necessary for your logic
Remove debug statements before saving
Avoid accessing deeply nested properties repeatedly
⚠️ Performance Impact
Each property access creates a dependency
Changes to any accessed property trigger template recalculation
Unused property access impacts performance unnecessarily
Debug statements should be removed in production
Last updated