Basic syntax
Liquid uses two main syntax structures:- Output Tags:
{{ ... }}— Display data from a variable or object. - Logic Tags:
{% ... %}— Execute conditional statements or loops.
Conditionals
Operators
==,!=,>,<,>=,<=and,orcontains(string or array)
liquid
if, elsif, else
liquid
unless
liquid
case / when
Use case / when to map a variable to specific values with a fallback else. This is useful when {{ subscription.language }} alone would generate invalid paths for unsupported languages.
liquid
Filters
Apply filters using{{ variable | filter }} to adjust how the data is displayed.
default
Assign a default value if the property is empty or does not exist.
liquid
date
The date filter converts a timestamp into another date format. The format for this syntax is the same as strftime. The input uses the same format as Ruby’s Time.parse.
Set dates as a unix timestamp in seconds with tags. This allows for use of both liquid syntax personalization and segmentation with Time Operators. For example, a tag might look like: bill_due : 1687968776
liquid
Result
liquid
Result
liquid
Result
now (or today) along with the date filter.
liquid
Result
The current time will be rendered in the message based on when the message is
sent to the recipient. If you are testing the message, you will see the
current time as when the test message was sent.
capitalize
This filter makes the first character of a string capitalized and converts the remaining characters to lowercase.
liquid
Result
round
This filter rounds a number to the nearest integer, or, if a number is passed as an argument, to that number of decimal places.
liquid
Result
pluralize
This filter returns the singular or plural form of a string based on a given number. The number must be a whole number and can be provided as a string. Both the singular and plural forms of a string must be provided.
liquid
Result
Iteration
for loops
Repeatedly executes a block of code. For a full list of attributes available within a for loop, see the Liquid for loop documentation.
liquid
Request Body
Result
limit & offset
Limits the loop to the specified number of iterations. For example, if you only want to show 4 products in a message, you could use Limits and Offsets to specify the number of products shown.
Data
liquid
Result
Data
liquid
Result
where
Creates an array including only the objects with a given property value, or any truthy value by default.
In this example, assume you have a list of products and you want to show your kitchen products separately. Using where, you can create an array containing only the products that have a type of kitchen.
Data
liquid
Result
String manipulation
Apply string filters to adjust how tag values or inline strings are displayed in messages.| Command | Description | Example | Example Output |
|---|---|---|---|
replace | Replaces a substring with another string. | {{ 'hello world' | replace: 'world', 'there' }} | hello there |
capitalize | Capitalizes the first letter of a string. | {{ 'hello' | capitalize }} | Hello |
upcase | Converts a string to uppercase. | {{ 'hello' | upcase }} | HELLO |
downcase | Converts a string to lowercase. | {{ 'HELLO' | downcase }} | hello |
strip | Removes leading and trailing whitespace from a string. | {{ ' hello ' | strip }} | hello |
strip_html | Removes all HTML tags from a string. | {{ '<p>hello</p>' | strip_html }} | hello |
truncate | Shortens a string to a specified length, adding an ellipsis (…) if needed. | {{ 'This is a long sentence' | truncate: 10 }} | This is a… |
truncatewords | Truncates a string after a certain number of words. | {{ 'This is a long sentence' | truncatewords: 2 }} | This is… |
replace_first | Replaces the first occurrence of a substring. | {{ 'hello world' | replace_first: 'world', 'there' }} | hello there |
prepend | Adds a string to the beginning of another string. | {{ 'world' | prepend: 'hello ' }} | hello world |
append | Adds a string to the end of another string. | {{ 'hello' | append: ' world' }} | hello world |
lstrip | Removes leading whitespace from a string. | {{ ' hello' | lstrip }} | hello |
rstrip | Removes trailing whitespace from a string. | {{ 'hello ' | rstrip }} | hello |
FAQ
Why is substitution not working?
- In-App Messages do not support property substitution.
- Tag substitution does not work when using “Send Test Message”.
- Tag keys must be alphanumeric, or use _ and - (no periods or spaces).
- Substitution does not appear in preview mode — send a real message to test.
When should I use default vs. if/else?
Use the default filter when only the variable value needs a fallback and the surrounding text stays the same.
liquid
Result (name = "Jon")
Result (name is empty)
if/else conditional logic when the surrounding text, punctuation, or sentence structure also needs to change based on whether the variable exists.
liquid
Result (name = "Jon")
Result (name is empty)
How do I control whitespace and newlines?
Use hyphens:{{- ... -}}, {%- ... -%} to trim surrounding whitespace.
See Whitespace control for more details.
How do I handle user-generated content?
Wrap user-generated text in{% raw %} and {% endraw %} to prevent Liquid parsing. See “raw” syntax.
Related pages
Message personalization
Overview of all personalization options including Liquid, Data Feeds, and custom events.
Data Feeds
Pull real-time data from your APIs into messages at send time.
Tags
Store key-value pairs on users for segmentation and Liquid personalization.
Templates
Create reusable message templates with Liquid personalization built in.