Skip to content

Liquid use case library

Looking for inspiration to craft the perfect personalization using Liquid? Take a look through our collection of Liquid use cases, outlined by category below.

Use the search bar or the checkboxes below to find the use cases that fit your need.

Anniversaries and holidays

Personalize messages based on a user’s anniversary year

This use case shows how to calculate a user’s app anniversary based on their initial sign-up date and display different messages based on how many years they are celebrating.

Explanation: Here, we use the reserved variable now to template in the current date and time in ISO 8601 format. The filters %B (month like “May”) and %d (day like “18”) format the current month and day. We then use the same date and time filters on the signup_date values to ensure we can compare the two values using conditional tags and logic.

Then we repeat three more variable statements to get the %B and %d for the signup_date, but also adding %Y (year like “2021”). This forms the date and time of the signup_date into just the year. Knowing the day and month lets us check if the user’s anniversary is today, and knowing the year tells us how many years it’s been—which lets us know how many years to congratulate them on!

Personalize messages based on a user’s birthday week

This use case shows how to find a user’s birthday, compare it to the current date, and then display special birthday messages before, during, and after their birthday week.

Explanation: Similar to the anniversary year use case, here we take the reserved variable now and use the %W filter (week such as week 12 out of 52 in a year) to get the number week of the year that the user’s birthday falls within. If the user’s birthday week matches the current week, we send them a message congratulating them!

We also include statements for last_week and next_week to further personalize your messaging.

Send campaigns to users in their birthday month

This use case shows how to calculate a user’s birthday month, check if their birthday falls in the current month, and if so, send a special message.

Explanation: Similar to the birthday week use case, except here we use the %B filter (month like “May”) to calculate which users have a birthday this month. A potential application could be addressing birthday users in a monthly email.

Avoid sending messages on major holidays

This use case shows how to send messages during the holiday period while avoiding the days of major holidays, when engagement is likely to be low.

Explanation: Here we assign the term today to the reserved variable now (the current date and time), using the filters %Y (year like “2023”), %m (month like “12”), and %d (day like “25”) to format the date. We then run our conditional statement to say that if the variable today matches the holiday days of your choice, then the message will be aborted.

The example provided uses Christmas Eve, Christmas Day, and Boxing Day (the day after Christmas).

App usage

Send messages in a user’s language if they haven’t logged a session

This use case checks if a user has logged a session, and if not, includes logic to display a message based on the language manually collected via a custom attribute, if any. If there is no language information tied to their account, it will display the message in the default language. If a user has logged a session, it will pull any language information tied to the user and display the appropriate message.

Explanation: Here, we’re using two grouped if statements, nested. The first if statement checks to see if the user has started a session by checking if the last_used_app_date is nil. This is because {{${language}}} is auto-collected by the SDK when a user logs a session. If the user hasn’t logged a session, we won’t have their language yet, so this checks if any language-related custom attributes have been saved, and based on that information, will display a message in that language, if possible.

The second if statement just checks for the standard (default) attribute because the user doesn’t have nil for the last_used_app_date, which means they’ve logged a session, and we have their language.

Personalize messages based on when a user last opened the app

This use case calculates the last time a user opened your app and will display a different personalized message depending on the length of time.

Show a different message if a user last used the app less than three days ago

This use case calculates how long ago a user used your app, and depending on the length of time, will display a different personalized message.

Countdowns

Add x days to today’s date

This use case adds a specific number of days to the current date to reference and add in messages. For example, you may want to send a mid-week message that shows events in the area for the weekend.

The plus value will always be in seconds, so we end with the filter %F to translate the seconds to days.

Calculate a countdown from a set point in time

This use case calculates the difference in days between a specific date and the current date. This difference can be used to display a countdown to your users.

Create a countdown for specific shipping dates and priorities

This use case captures different shipping options, calculates the length of time it would take to receive, and displays messages encouraging users to purchase in time to receive their package by a certain date.

Create a countdown in days

This use case calculates the time left between a specific event and the current date and displays how many days are left until the event.

Create a countdown from days to hours to minutes

This use case calculates the time left between a specific event and the current date. Depending on the time left until the event, it will change the time value (days, hours, minutes) to display different personalized messages.

For example, if there are two days until a customer’s order arrives, you might say, “Your order will arrive in 2 days.” Whereas if there’s less than a day, you could change it to “Your order will arrive in 17 hours.”

Show how many days left until a certain date

This use case calculates the difference between the current date and future event date and displays a message noting how many days until the event.

Display how many days left until a custom date attribute will arrive

This use case calculates the difference in days between the current and future dates and displays a message if the difference matches a set number.

In this example, a user will receive a message within two days of the custom date attribute. Otherwise, the message will not be sent.

Display how much time is left, and abort the message if there’s only x time left

This use case will calculate how long until a certain date, and depending on the length (skipping messaging if the date is too soon), will display different personalized messages.

For example, “You have x hours left to buy your ticket for London”, but don’t send the message if it’s within two hours of flight time for London.

In-app message to send x days before users’ membership ends

This use case captures your membership expiry date, calculates how long until it expires, and displays different messages based on how long until your membership expires.

Personalize in-app messages based on users’ date and language

This use case calculates a countdown to an event, and based on a user’s language setting, will display the countdown in their language.

For example, you might send a series of upsell messages to users once a month to let them know how long an offer is still valid with four in-app messages:

  • Initial
  • 2 days left
  • 1 day left
  • Final day

Template in the date 30 days from now, formatted as month and day

This use case will display the date 30 days from now to use in messaging.

Custom attribute

Personalize a message based on matching custom attributes

This use case checks if a user has specific custom attributes and, if so, will display different personalized messages.

Subtract two custom attributes to display the difference as a monetary value

This use case captures two monetary custom attributes, then calculates and displays the difference to let users know how far they have to reach their goal.

Reference a user’s first name if their full name is stored in the first_name field

This use case captures a user’s first name (if both first and last name are stored in a single field) and then uses this first name to display a welcome message.

Explanation: The split filter turns the string held in {{${first_name}}} into an array. By using {{name[0]}}, we then only refer to the first item in the array, which is the user’s first name.

Custom event

Abort push notification if a custom event is within two hours of now

This use case calculates the time until an event, and depending on the amount of time left, will display different personalized messages.

For example, you may want to prevent a push from going out if a custom event property will pass in the next two hours. This example uses the scenario of an abandoned cart for a train ticket.

Send a campaign each time a user performs a custom event three times

This use case checks if a user has performed a custom event three times, and if so, will display a message or send a campaign.

Send a message to users who have only purchased from one category

This use case captures a list of the categories a user has purchased from, and if only one purchase category exists, it will display a message.

Track how many times a custom event occurred over the past month

This use case calculates the number of times a custom event has been logged between the 1st of the current month and the previous month. You can then run an users/track call to update store this value as a custom attribute. Note that this campaign would need to run for two consecutive months before monthly data can be used.

Language

Display month names in a different language

This use case will display the current date, month, and year, with the month in a different language. The example provided uses Swedish.

Display an image based on a user’s language

This use case will display an image based on a user’s language. Note that this use case has only been tested with images uploaded to the Braze media library.

Personalize messaging based on day of the week and user’s language

This use case checks the current day of the week and, based on the day, if the user’s language is set to one of the language options provided, it will display a specific message in their language.

The example provided stops on Tuesday but can be repeated for each day of the week.

Miscellaneous

Avoid sending emails to customers that have blocked marketing emails

This use case takes a list of blocked users saved in a Content Block and checks those blocked users are not communicated to or targeted in upcoming campaigns or Canvases.

Explanation: Here we check if your potential recipient’s email is in this list by referencing the Content Block of blocked emails. If the email is found, the message will not send.

Use a customer’s subscription state to personalize content in messages

This use case takes a customer’s subscription state to send personalized content. Customers are who subscribed to a specific subscription group will receive an exclusive message for email subscription groups.

Capitalize the first letter of every word in a string

This use case takes a string of words, splits them into an array, and capitalizes the first letter of each word.

Explanation: Here we’ve assigned a variable to our chosen string attribute, and used the split filter to split the string into an array. We’ve then used the for tag to assign the variable words to each of the items in our newly created array, before displaying those words with the capitalize filter and the append filter to add spaces between each of the terms.

Compare custom attribute value against an array

This use case takes a list of favorite stores, checks if any of a user’s favorite stores are in that list, and if so, will display a special offer from those stores.

Create an upcoming event reminder

This use case allows users to set up upcoming reminders based on custom events. The example scenario allows a user to set a reminder for a policy renewal date that is 26 or more days away, where reminders are sent 26, 13, 7, or 2 days before the policy renewal date.

With this use case, the following should go in the body of a webhook campaign or Canvas step.

Find a string within an array

This use case checks if a custom attribute array contains a specific string, and if it exists, will display a specific message.

Find the largest value in an array

This use case calculates the highest value in a given custom attribute array to use in user messaging.

For example, you may want to show a user what the current high score is or the highest bid on an item.

Find the smallest value in an array

This use case calculates the lowest value in a given custom attribute array to use in user messaging.

For example, you may want to show a user what the lowest score is or the cheapest item.

Query the end of a string

This use case queries the end of a string to use in messaging.

Query values in an array from a custom attribute with multiple combinations

This use case takes a list of soon-to-be-expired shows, checks if any of a user’s favorite shows are in that list, and if so, will display a message notifying the user that they will expire soon.

Format a string into a phone number

This use case shows you how to index the phone_number user profile field (by default, formatted as a string of integers), and reformat it based on your local phone number standards. For example, 1234567890 to (123)-456-7890.

Platform targeting

Differentiate copy by device OS

This use case checks what platform a user is on, and depending on their platform, will display specific messaging.

For example, you may want to show mobile users shorter versions of message copy while showing other users the regular, longer version of the copy. You could also show mobile users certain messaging relevant to them but wouldn’t be relevant to Web users. For example, iOS messaging might talk about Apple Pay, but Android messaging should mention Google Pay.

Target only a specific platform

This use case will capture the users’ device platform, and depending on the platform, will display a message.

For example, you may want to only send a message to Android users. This can be used as an alternative to selecting an app within the Segmentation tool.

Target only devices with a specific OS version

This use case checks if a user’s OS version falls within a certain set of versions and if so, will display a specific message.

The example used sends a warning to users on an OS version 10.0 or earlier that they are phasing out support for the user’s device OS.

Target only web browsers

This use case checks if a user’s target device runs on Mac or Windows and, if so, will display a specific message.

The following use case checks if a web users is on iOS or Android and, if so, will display a specific message.

Target a specific mobile carrier

This use case checks if a user’s device carrier is Verizon, and if so, will display a specific message.

For push notifications and in-app message channels, you can specify the device carrier in your message body using Liquid. If the recipient’s device carrier doesn’t match, the message won’t be sent.

Time zones

Personalize a message depending on a user’s time zone

This use case displays different messages based on a user’s time zone.

Append the CST time zone to a custom attribute

This use case displays a custom date attribute in a given time zone.

Option 1:

Option 2:

Insert a timestamp

This use case displays a message that includes a timestamp in their current time zone.

The following example provided will display the date as YYYY-mm-dd HH:MM:SS, such as 2021-05-03 10:41:04.

Only send a Canvas push during a window of time in a user’s local time zone

This use case checks a user’s time in their local time zone, and if it falls within a set time, it will display a specific message.

Send a reoccurring in-app message campaign between a window of time in a user’s local time zone

This use case will display a message if a user’s current time falls within a set window.

For example, the following scenario lets a user know that a store is closed.

Send different messages on weekdays versus weekends in a user’s local time zone

This use case will check if a user’s current day of the week is Saturday or Sunday, and depending on the day, will display different messages.

Send different messages based on time of day in a user’s local time zone

This use case will display a message if a user’s current time falls outside a set window.

For example, you may want to tell a user about a time-sensitive opportunity that depends on the time of day.

Week/Day/Month

Pull the previous month’s name into a message

This use case will take the current month and display the previous month to be used in messaging.

You can alternatively use the following to get the same result.

Send a campaign at the end of every month

This use case will check if the current date falls within a list of dates, and depending on the date, will display a specific message.

Send a campaign on the last (weekday) of the month

This use case captures the current month and day and calculates if the current day falls within the last weekday of the month.

For example, you may want to send a survey to your users on the last Wednesday of the month asking for product feedback.

Send a different message each day of the month

This use case checks if the current date matches one on a list, and depending on the day, will display a distinct message.

Send a different message each day of the week

This use case checks the current day of the week, and depending on the day, will display a distinct message.

HOW HELPFUL WAS THIS PAGE?
New Stuff!