Skip to content

Filters

This reference article provides an overview of filters in Liquid, and covers which filters are supported by Braze. Looking for ideas on how you can use these filters? Check out our Liquid use case library.

Filters are how you can modify the output of numbers, strings, variables, and objects in Liquid. You can use filters to reformat static or dynamic text, such as changing a string from lowercase to uppercase or to perform mathematical operations, like addition or division.

Filter syntax

Filters must be placed within an output tag {{ }} and are denoted by a pipe character |.

1
{{"Big Sale" | upcase}}
1
BIG SALE

In this example, Big Sale is a string, and upcase is the filter being applied.

Syntax for multiple filters

You can use multiple filters on one output. They are applied from left to right.

1
 {{ "Big Sale" | upcase | remove: "BIG" }}
1
SALE

Array filters

Array filters are used to change the output of arrays.

Color filters

Color filters are not supported in Braze.

Font filters

Font filters are not supported in Braze.

Math filters

Math filters allow you to perform mathematical operations. If you use multiple filters on one output, they will be applied from left to right.

Mathematical operations with custom attributes

Keep in mind that you can’t perform mathematical operations between two custom attributes.

1
{{custom_attribute.${current_rewards_balance} | plus: {{custom_attribute.${giftcard_balance}}}}}

This example wouldn’t work because you can’t reference multiple custom attributes in one line of Liquid. Instead, you would need to assign a variable to at least one of these values before the math functions take place. Adding two custom attributes together would require two lines of Liquid:

  1. One to assign the custom attribute to a variable,
  2. One to perform the addition.

Use case: Calculate current balance

Let’s say we want to calculate a user’s current balance by adding their gift card balance and rewards balance.

  1. Use the assign tag to substitute the custom attribute of current_rewards_balance with the term “balance”. This means that you now have a variable named balance, which you can manipulate.
1
{% assign balance = {{custom_attribute.${current_rewards_balance}}} %}
  1. Use the plus filter to combine each user’s gift card balance with their rewards balance, signified by the {{balance}} object.
1
2
{% assign balance = {{custom_attribute.${current_rewards_balance}}} %}
You have ${{custom_attribute.${giftcard_balance} | plus: {{balance}}}} to spend!
1
You have $35 to spend!

Money filters

If you’re updating a user on their purchase, an account balance, or anything regarding money, you should use money filters. Money filters ensure that your decimals are in the proper place and that no piece of your update is lost (like that pesky 0 at the end).

Shopify money filter versus Braze money filter

In the event you are inputting a custom attribute (like account_balance), you should always use the money filter to put your decimals in the proper place and prevent zeros from dropping off the end of any numbers:

1
${{custom_attribute.${account_balance} | money}}

The money filter in Braze differs from Shopify because it doesn’t automatically apply decimal points according to a preset setting. For example, take the following scenario where rewards_redeemed contains a value of 145:

1
${{event_properties.${rewards_redeemed} | money }}
1
$145.00

According to Shopify’s money filter, this should have an output of $1.45, however in Braze, this will have an output of $145.00. As a workaround, we can use the divided_by filter to manipulate the number into a decimal, before applying the money filter:

1
${{event_properties.${rewards_redeemed} | divided_by: 100.00 | money }}
1
$1.45

String filters

String filters are used to manipulate the outputs and variables of strings. Strings are a combination of alphanumeric characters and must be wrapped in straight quotes.

Additional filters

The following general filters serve many purposes, including formatting or converting content.

You can find more supported filters, such as encoding and URL filters, on our Advanced Filters page.

Date filter

The date filter can be used to convert a timestamp into a different date format. You can pass in parameters to the date filter to reformat the timestamp. For examples of these parameters, refer to strfti.me.

For example, let’s say that the value of date_attribute is the timestamp 2021-06-03 17:13:41 UTC.

1
{{custom_attribute.${date_attribute} | date: '%b %d'}}
1
03 June

In addition to the strftime formatting options, Braze also supports converting a timestamp to Unix time with the %s date filter. For example, to get the date_attribute in Unix time:

1
{{custom_attribute.${date_attribute} | date: '%s' }}
1
1433351621

Time zone filter

In addition to the filters that you’ll find listed in Shopify’s documentation, Braze also supports the time_zone filter.

The time_zone filter takes a time, a time zone, and a date format and returns the time in that time zone in the specified date format. For example, let’s say that the value of {{custom_attribute.$date_attribute}}} is 2021-08-04 9:00:00 UTC:

1
{{custom_attribute.${date_attribute} | time_zone: 'America/Los_Angeles' | date: '%a %b %e %T' }}
1
Wed August 4 2:00:00

You can also use the reserved variable now to access the current date and time for manipulation.

1
{{ 'now' | date: '%Y-%m-%d %H:%M:%S' }}
1
2021-08-04 18:13:13
HOW HELPFUL WAS THIS PAGE?
New Stuff!