LIQUID FOR TECHNICAL MARKETERS: Filters

Liquid Filters are one of the 3 types of Liquid code that we mentioned in a previous video.

Filters take your Liquid variable and change the output, allowing us Marketers to be flexible in our personalization.

Some Filters have what’s called a parameter or multiple parameters, and you can also mix and match Filters.

Watch the full video to learn more about Liquid Filters!

— — — — — — — — — — —

Braze Liquid Filters Documentation: https://www.braze.com/docs/user_guide/personalization_and_dynamic_content/liquid/filters/

🗣️ WATCH FULL YOUTUBE VIDEO HERE 🗣

https://youtu.be/6iSi-3IEWHM

What’s up everyone, my name is Allan, Founder and Consultant at For Now Marketing, and welcome to LIQUID FOR TECHNICAL MARKETERS!

If your goal is to improve your Liquid coding skills, then please:

  1. like this video
  2. subscribe to our channel
  3. watch this video all the way to the end
  4. and keep an eye out for more videos in the future.

Today, we’re going to talk more in depth about the Liquid Filters and how to use them.

Let’s get started.

Liquid Filters List

Before we get started, let’s first quickly scroll down this long list of Filters provided in the Liquid basic documentation. There are tons of useful filters, some that I use very, very regularly, and some that comes in handy occasionally.

Please take some time to look through every single one of these Filters, just to expose yourself to all the different capabilities of Liquid Filters. You might be surprised to find some solutions to issues you’ve been having in your Marketing Personalization.

One thing to note is that Braze supports most of these Filters, but not all. Be sure to cross reference between this Shopify doc and the Braze Doc called Filters, linked in the Youtube description below.

No Parameters

All right, let’s talk about Parameters for Liquid Filters.

A handful of Filters don’t require any Parameters, meaning all you need to do is insert the pipeline character and the Filter, and the Filter just goes to work. For example:

{% assign name = “allan” %}

{{ name | capitalize }}

capitalize is an example of a Filter that doesn’t require a parameter. the capitalize Filter just takes the variable and capitalizes it, whether the variable already starts with a capital letter or not.

By the way, one quick thing to note here is that Filters can also be used directly inside the Assign Tag. So here’s a different way to write this Liquid snippet that would have the exact same result:

{% assign name = “allan” | capitalize %}

{{ name }}

In this situation, the capitalize Filter is used directly inside the assign tag, so I don’t need to re-include the Filter when we reference the name variable. And sometimes, it makes more sense to use the Filters directly inside the Assign Tag.

One Parameter

This time, let’s look at a Filter that does have a required parameter. All the Math Filters require a parameter, so let’s look at those.

For example, let’s start with the plus Filter which does exactly what it says: it adds a number to our variable. What would happen if we used our plus Filter without any parameters, like the example below?

{% assign number = 7 %}

{{ number | plus }}

What are we adding to our variable number? How much should we add? Liquid has no idea, because we didn’t use the Parameter that the plus Filter requires. The plus Filter will look for a number along with the Filter that will be added to our variable. So here’s a correct example:

{% assign number = 7 %}

{{ number | plus: 2 }}

To add a Parameter to our Filter, you add the colon, followed by the value for that Parameter. By the way, to throw in another key term, specific parameter values are called Arguments. So in our case, the 2 would be our Argument, which follows the Parameter requirement for the plus Filter.

Multiple Parameters

Let’s look at another example that requires two parameters, the replace Filter, which is a very useful one that has saved my life so many times.

The replace Filter requires two parameters: the Filter will look for any instances of the first argument, and when it finds that exact match, the Filter will REPLACE the first argument with the second argument.

Here’s an example:

{% assign liquid_status = “Liquid Level: Beginner” %}

Here we have a String called liquid_status that will render “Liquid Level: Beginner”.

However, you watched all the Liquid For Technical Marketers videos, and now your Liquid Level is at Proficient.

Using the replace Filter, we can look for any instances of the String “Beginner” and replace it with the String “Proficient”. Here’s what that looks like.

{{ liquid_status | replace: “Beginner”, “Proficient” }}

By the way, the order of the parameters are crucial, so be sure to read the Liquid documentation to confirm how each Filter and their parameters work! If we were to accidentally switch up the two parameters here, nothing would happen because there’s no instance of the String “Proficient” inside our variable liquid_status.

Mix & Match

For our last example, let’s go back to our Math Filters to see an example where we mix & match multiple Filters. Yes, we can use as many Filters as we want, and the subsequent Filters simply follow the same syntax of pipeline characters and colons.

Remember those magic math operations from elementary school? Let’s try one using Liquid. First, here’s the math operation steps.

  1. Think of a number.
  2. Multiply it by 3.
  3. Add 6.
  4. Divide this number by 3.
  5. Subtract the number from Step 1 from the answer in Step 4.

And here’s how that would look like in a single Liquid line using multiple Filters. First, let’s pick our random number.

{% assign my_number = 7 %}

Now, time for our magic:

{{ my_number | times: 3 | plus: 6 | divided_by: 3 | minus: my_number }}

This is an example of using multiple Filters within a single line. Also, one final thing to note is that I actually used a variable, in fact, the exact same variable my_number, for the argument for the last Filter minus. So you certainly can use other variables as Filter arguments, and you can even use the same variable as the one you’re starting with.

By the way, the answer to this magic math operation is always 2, no matter what you choose as your starting number. Try it yourself!

Thank You!

That’s it for today! In this video, we talked about many different possible ways to use Filters, and once again, if you haven’t already, we strongly recommend you go to the Liquid basic documentation and read through every single Filters listed there.

Thank you for watching, and see you next time!

allan@fornowmarketing.com

fornowmarketing.com

Previous
Previous

BRAZE LIQUID: Logical Operators (and/or)— Liquid For Technical Marketers

Next
Next

LIQUID FOR TECHNICAL MARKETERS: Assign & Capture