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:

{{ cart.cost.total }}

Control Tags

Control flow using special tags:

{% if customer.loggedIn %}
  Hello, customer!
{% endif %}

Comments

Document your code:

{# Quick inline comment #}
{% comment %}
  Detailed explanation here
{% endcomment %}

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 identifier

    • title (string): Product variant title

    • selectedOptions (array): Selected variant options

      • name (string): Option name (e.g., "Size")

      • value (string): Option value (e.g., "Small")

    • product (object): Parent product information

      • id (string): Product identifier

      • vendor (string): Product vendor name

      • productType (string): Product category/type

    • requiresShipping (boolean): Whether the item needs shipping

    • sku (string): Stock keeping unit

attributes

  • Type: array

  • Description: Custom attributes attached to the line item

  • Properties:

    • key (string): Attribute key

    • value (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 key

    • value (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 costs

    • subtotal (number): Sum of line items before tax/shipping

    • tax (number): Total tax amount

    • shipping (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 method

    • type ('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 selected

    • code (string): Shipping method identifier

    • title (string): Display name

    • cost.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 identifier

    • value (string): Metafield value

    • namespace (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

Filter
Description
Parameters

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

Filter
Description
Parameters

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

Filter
Description
Parameters

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

Was this helpful?