HomeGuidesAPI Reference
ChangelogHelp CenterCommunityContact Us
Guides
These docs are for v2023-10-15. Click to read the latest docs for v2024-10-15.

Use filters to customize variables

Learn how filters allow you to customize the format and content of variables in the messages you send, and how to use them to customize your variables.

For a list of filters available to use in the template editor, reference Klaviyo's variable filters glossary

Before you begin

Before you begin, become familiar with how Klaviyo’s variables and template tags work. In order to use filters on variables, you’ll need to be able to identify the correct base variables and add them to your template. 

How filters work

Filters are applied to variables to adjust what displays in a message. Some use cases for filters are:

  • Apply consistent capitalization to a piece of text (for example, you can use the upper filter to take any variable and make it all uppercase)
  • Adjust a base price to reflect a promotion or discount using the multiply filter 
  • Set the number of decimal places to display for a number variable using the floatformat filter

For a list of supported filters, reference our variable filters glossary

Apply a filter to a variable

To apply a filter to a variable, the following elements should be added:

  • A pipe symbol ( | ) after the variable name
  • The filter name 
  • If the filter takes any arguments, add a colon, followed by the argument(s) 

Do not add in any additional spaces. Here is an example of a variable with a filter applied:

{{ item.price|floatformat:2 }}

In this example, item.price is the variable name, floatformat is the filter, and 2 is the argument required by the filter. 

If the argument is a piece of text, it needs to be surrounded by single quotation marks. Quotation marks are not needed if the argument is a number. Reference Klaviyo’s variable filters glossary for examples. 

Tips for using filters

If you’re copying filters and pasting them into your template, make sure to paste as plain text to avoid pasting in formatting along with the filter itself. To paste as plain text, use the paste as plain text keyboard shortcut (Ctrl+Shift+V or Cmd+Shift+V). 

It’s important to ensure the data referenced in your variables is appropriate for the filter being used. Some filters can only be applied to string (text) data types, while others only work on lists or numbers. If the filter isn’t working as expected, review the event or profile data you’re using to ensure it is the correct type. 

Applying multiple filters

If needed, you can apply multiple filters to a single variable. To do so, connect each filter using a pipe symbol ( | ), and consider that the filters will generally be applied in order (from first to last). Here are some examples of variables with multiple filters applied: 

{{ first_name|title|default:'there' }}

In this example, the first filter applies title casing to the recipient’s first name, and the second filter supplies a default word to be used if no first name has been provided. Title casing will not be applied to the default value, “there”, because the filters are evaluated and applied in order. 

{{ item.price|multiply:.8|floatformat:2 }}

In this example, the first filter multiplies the base item price by .8 (to show the price if a 20% off coupon has been applied), and the second filter specifies that two decimal places should appear. 

Additional resources