Skip to content

Operators

Liquid supports many operators that can be used in your conditional statements. This page covers the operators that Liquid supports and provides use cases of how you can use them in your messages.

This table lists the operators that are supported. Note that parentheses are invalid characters in Liquid and prevents your tags from working.

Syntax Operator Description
== equals
!= does not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to
or condition A or condition B
and condition A and condition B
contains checks to see if a string or string array contains a string

Tutorials

Let’s go through a few tutorials to learn how to use these operators for your marketing campaigns:

Choose message with an integer custom attribute

Let’s send push notifications with personalized promotional discounts to users who have or haven’t made purchases. The push notification will use an integer custom attribute called total_spend to check a user’s total spend.

  1. Write a conditional statement using the greater than (>) operator to check if a user’s total spend is greater than 0, indicating they’ve made a purchase. Then, create a message to send to those users.
  1. Add the {% else %} tag to capture users whose total spend equals 0 or doesn’t exist. Then, create a message to send to those users.
  1. Close the conditional logic with the {% endif %} tag.

A push notification composer with the full Liquid code from the tutorial.

Full Liquid code

Now if a user’s “Total Spend” custom attribute is greater than 0, they will get the message:

If a user’s “Total Spend” custom attribute does not exist or is equal to 0, they will get the following message:

Choose message with a string custom attribute

Let’s send push notifications to users, and personalize the message based on each user’s most recently played game. This will use a string custom attribute called recent_game to check which game a user has last played.

  1. Write a conditional statement using the equals (==) operator to check if a user’s most recent game is Awkward Dinner Party. Then, create a message to send to those users.
  1. Use the elsif tag with the equals (==) operator to check if user’s most recent game is Proxy War 3: War of Thirst. Then, create a message to send to those users.
  1. Use the elsif tag with the does not equal (!=) and “and” (&&) operators to check if the user has a recent game (meaning the value isn’t blank), and that the game isn’t Awkward Dinner Party or Proxy War 3: War of Thirst. Then, create a message to send to those users.
  1. Add the {% else %} tag to capture users who don’t have a recent game. Then, create a message to send to those users.
  1. Close the conditional logic with the {% endif %} tag.
Full Liquid code

A push notification composer with the full Liquid code from the tutorial.

Now, if a user last played Awkward Dinner Party, they’ll receive this message:

If a user’s most recent game is Proxy War 3: War of Thirst, they will receive this message:

If a user has recently played a game that wasn’t Awkward Dinner Party or Proxy War 3: War of Thirst, they’ll get this message:

If a user hasn’t played any games or that custom attribute doesn’t exist on their profile, they’ll get this message:

Abort message based on location

You can abort a message based on just about anything. Let’s abort a message if a user isn’t based in a specified area, as they might not qualify for the promotion, show, or delivery.

  1. Write a conditional statement using the equals (==) operator to check if the user’s time zone is America/Los_Angeles, then create a message to send to those users.
  1. To avoid sending messages to users outside the America/Los_Angeles time zone, wrap {% else %} and {% endif %} tags around an {% abort_message () %} tag.
Full Liquid code

A push notification composer with the full Liquid code from the tutorial.

You can also abort messages based on Connected Content.

HOW HELPFUL WAS THIS PAGE?
New Stuff!