Skip to main content

Overview

Liquid is a templating language OneSignal uses to insert dynamic values into messages at send time. You write Liquid expressions in supported fields; OneSignal replaces them with the matching value for each recipient just before delivery.
Liquid
OneSignal supports two syntax structures: For the language itself, see the official Liquid documentation. This page focuses on the parts that work in OneSignal and the OneSignal-specific data objects you can reference. Liquid support varies by channel and by field. Most notably, in-app messages support only Tag substitution (no journey.*, message.*, subscription.*, or user.* objects), and the push data field does not support Liquid at all. See Supported fields by message type for the full per-channel breakdown.

Prerequisites


Conditionals

if, elsif, else

Render different content based on a value.
Liquid

unless

Inverse of if — runs the block when the condition is false.
Liquid
Tag values are stored as strings. If you compare a numeric tag, either compare against a string (level == "1") or cast first with {% assign n = level | plus: 0 %} and then compare numerically.

case / when

Map a single variable to specific values with a fallback else. Useful when interpolating the variable directly would produce invalid output (for example, an unsupported language code in a URL).
Liquid

Operators

You can use these operators inside if, elsif, and unless. Liquid evaluates conditions right-to-left — not by operator precedence — and does not support parentheses for grouping. Refactor with nested if blocks if you need explicit grouping.
Liquid
If you tried to read this as (false and true) or true, you would expect it to render — but Liquid groups the rightmost two operands first, so the final check is false and ....

Variables

assign

Create a reusable variable inside a template. Useful for shortening references and for casting tag values to numbers.
Liquid

Bracket notation for special characters

Use bracket notation when a key contains spaces, hyphens, or other non-alphanumeric characters.
Liquid

Filters

Apply filters with {{ variable | filter }}. You can chain filters: {{ name | downcase | capitalize }}.

default

Render a fallback value when the input is empty, null, or undefined.
Liquid

date

Format a timestamp using strftime directives. The input can be a Unix timestamp, a parseable date string, or the special words "now" / "today".
"now" is evaluated per recipient at send time. In test sends, it reflects when the test was sent.
From a Unix timestamp tag: Store dates as Unix timestamps (seconds) on user tags. The same tag then works for both Liquid date formatting and Time Operator segmentation — for example, a tag like bill_due: 1687968776.
Liquid
Result
From a date string:
Liquid
Result
Current time at send:
Liquid
Result

round

Round a number to the nearest integer, or to a specified number of decimal places.
Liquid
Result

pluralize

Return the singular or plural form of a string based on a count. The count must be a whole number; strings that look like whole numbers are accepted.
pluralize is a OneSignal addition — it is not part of the standard Shopify Liquid filter set. Use it inside OneSignal templates only.
Liquid
Result

Math filters

Useful for casting strings to numbers and for arithmetic inside templates.

Array filters

Used with arrays from custom_data, Custom Event properties, or Tags.

where example

Given a list of products, build a sub-list containing only the kitchen ones:
Liquid
Custom data
Result

String filters

Apply string filters to adjust how values render.

Iteration

for loops

Iterate over an array of items. For the full attribute list, see the Liquid for loop documentation.
Liquid
Custom data
Result
The {% else %} branch renders when the array is empty or undefined:
Result (products is empty)
for loops can degrade delivery performance in rare cases. Be mindful of loop usage on high-volume sends. Push channel fields contents, headings, subtitle, apns_alert, and url do not support for loops.

forloop variables

Inside a for block, Liquid exposes a forloop object with metadata about the current iteration. Useful for separators:
Liquid

limit and offset

Restrict how many items a loop iterates over and where it starts.
Liquid
Result

FAQ

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)
Use if/else when the surrounding text, punctuation, or sentence structure also needs to change.
Liquid
Do not use default when the sentence structure changes. For example, {{ name | default: "Shop your favorites" }}, shop your favorites would render as “Shop your favorites, shop your favorites” when the name is empty. If the fallback changes more than the variable, use if/else.

How do I control whitespace and newlines?

Use hyphens inside the tag delimiters to trim surrounding whitespace: {{- ... -}} and {%- ... -%}. See Whitespace control for the full rules.

How do I include literal {{ or {% in the output?

Wrap the section in {% raw %} and {% endraw %} so Liquid does not parse it. This is the right tool for user-generated content that may contain Liquid-looking characters. See Liquid raw syntax.
Push payload

What happens if a Liquid expression references a missing value?

The expression renders as an empty string and the message still sends. Wrap optional values in | default: "fallback" so the surrounding sentence still reads correctly.

Personalize with properties

Use Tags, External ID, and other stored properties to personalize messages with Liquid.

Personalize with Custom Events

Reference Custom Event properties in Journey messages with journey.first_event and related objects.

Personalize with API custom_data

Send dynamic, message-specific data through the Create Message API and render it with Liquid.

Data Feeds

Pull real-time data from your APIs into messages at send time.

Dynamic Content with CSV

Personalize push, email, and SMS at scale using CSV uploads and the dynamic_content Liquid object.