Manipulating Message Content (Filters)

Filters can be used to reformat static or dynamic content. For example, you can use a filter to reformat a string from uppercase to lowercase or to perform mathematical operations.

Filters should be placed within an output tag {{ }} and should be separated from the value that you’d like to reformat with a pipe character |.

For example, the output of {{"Big Sale" | upcase}} is “BIG SALE”.

Or, let’s say that you’re running a campaign where you’re offering customers 50 rewards points if they make a purchase and you’ve stored their current rewards balance as a custom attribute.

You can use the add filter to show customers what their rewards balance would be if they made an additional purchase:

1
Hey Marion, make a purchase today to earn 50 points and bring your rewards balance to {{custom_attribute.${current_rewards_balance} | plus: 50}}.

Math Filters

Math filters allow you to complete basic mathematical operations in the message composer. For example, you can add or subtract static values or variables to and from numeric personalizable attributes, other static values and or other variables. In this example, let’s assume that the value of current_rewards_balance is 50.

Input:

1
Hey Marion, make a purchase today to earn 50 pts and bring your rewards balance to {{custom_attribute.${current_rewards_balance} | plus: 50}}.

Output:

1
Hey Marion, make a purchase today to earn 50 pts and bring your rewards balance to 100.

You cannot perform mathematical operations with two custom attributes.

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

You must first define one of the custom attributes as a variable and then perform the operation with the variable and the remaining attribute. Use a variable tag to capture the value of one of the custom attributes:

1
2
{% assign balance = {{custom_attribute.${current_rewards_balance}}} %}
{{custom_attribute.${giftcard_balance} | plus: balance}}

String Filters

String filters are used to manipulate the outputs and variables of strings. For example, you can capitalize a string.

Array Filters

Array filters can be used to manipulate the outputs of arrays. All array filters listed here are compatible with Braze’s message composer.

For example, the first filter can used to template the first value in an array into the message composer. Please note that the first value in an array custom attribute array is the most recently added value.

The filter {{custom_attribute.${my_array} | first}} will yield the most recently added value. If my_array is a custom attribute array that consists of “apple, orange, banana” the output of {{custom_attribute.${my_array} | first}} will be “apple”.

Date Filters

Date filters can be used to convert a timestamp into a different date format. Let’s say that the value of date_attribute is the timestamp 2015-06-03 17:13:41 UTC.

The filter {{custom_attribute.${date_attribute} | date: "%b","%d"}} will reformat this timestamp to “03 June”. There are many other date formatting options which you can find here.

In addition to these formatting options, we also support converting a timestamp to Unix time with the ``%s` date filter.

For example, to get the date_attribute in Unix time, you’d input the following and get the integer 1433351621 as an output:

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

In addition to the filters that you’ll find listed in Shopify’s documentation, we also support the “time_zone” filter.

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

Input:

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

Output:

1
Fri April 3 2:00:00

Additionally you can access the current time for manipulation by doing something like the following:

1
{{ 'now' | date: '%Y-%m-%d %H:%M:%S' }}

Which will return something like:

1
2016-08-22 18:13:13
WAS THIS PAGE HELPFUL?