Glossary of variable filters
Learn how to use variable filters to adjust and manipulate the data you show in an SMS or email message.
Klaviyo’s email and SMS editors support most built-in Django filters, in addition to a small number of custom filters. For example, the title filter can be used to apply title case formatting to a piece of text pulled in from a customer profile or event data. In this glossary, you will find a compilation of different filters, what they do, and examples of how they should be formatted.
Learn how to use these filters to customize the profile and event data you use in messages to your subscribers.
Glossary
Filter | Description | Examples |
---|---|---|
add | Adds an argument to your variable, where both the argument and variable are integers. If either number is a float (a non-integer number), all decimals will be ignored. To add together floats, see floatadd below | If your_variable is 5, {{ your_variable|add:2 }} will render as 7 |
base64_encode | Encodes a value in Base-64 format. A common use case is encoding an email address so it can be passed within a UTM parameter. | {{ person.email|base64_encode }} |
concat | Combines two strings together. | If your variable is "hello", {{ your_variable|concat:' world' }} will render as "hello world" |
count | Returns the number of characters in a string. | If your variable is “hello”, {{ your_variable|count }} will return 5 |
default | Supplies a default value to be used if the variable is empty. | “Hey {{ first_name|default:'friend' }}!” would render like this, given no first name is provided: Hey friend! |
dictfilter | Filters a dictionary to match the criteria of an argument. This filter takes three arguments: 1. Item key 2. Operator 3. Comparison value | If your variable is [{'a': 2}, {'a': 3}], {{ your_variable|dictfilter:"a>2" }} would render as [{'a': 3}] |
divide | Divides a variable by the number supplied. | If your variable is 10, {{ your_variable|divide:4 }} will render as 2.5 |
escape | Escapes a string’s HTML. The specific replacements made are: < is converted to < > is converted to > ' (single quote) is converted to ' " (double quote) is converted to " & is converted to & Use this filter if your event data passes HTML-encoded data, to allow it to display without extra symbols. | {{ your_variable|escape }} |
floatadd | Adds the argument to a variable’s value, where both the argument and variable are numbers. | If your variable is 4.1, {{ your_variable|floatadd:2.2 }} will render as 6.3 |
floatformat | Specifies the number of decimal places to display. A common use case is to show a price with two decimal places, regardless of how many digits are supplied. | If your variable is 5 or 5.0003, {{ your_variable|floatformat:2 }} will render as 5.00 |
format_date_string | Formats a date variable as a string following this format: Feb. 11, 2016, 4:46 p.m. | {{ your_variable|format_date_string }} |
gt | Within an if statement, compares whether a variable’s value is greater than the filter’s argument. | If your_variable is 3, {% if your_variable|gt:2 %} will evaluate as true |
gte | Within an if statement, compares whether a variable’s value is greater than or equal to the filter’s argument. | If your_variable is 2, {% if your_variable|gte:2 %} will evaluate as true |
httpize | Prepends “http:// ” to a web address, if not already present | If your variable is "www.klaviyo.com ", {{ your_variable|httpize }} will render as "http://www.klaviyo.com " |
httpsize | Prepends “https:// ” to a web address, if not already present | If your variable is "www.klaviyo.com ", {{ your_variable|httpsize }} will render as "'https://www.klaviyo.com " |
join | Converts a list to a string, with all list items connected by the string you supply. | If your variable contains the list ['a', 'b', 'c'], {{ your_variable|join:'//' }} will render as a // b // c |
list_to_string | Converts a list into a string, with proper list punctuation. | If your variable contains the list ['apple', 'banana', 'orange'], {{ your_variable|list_to_string }} will render as apple, banana and orange |
lookup | Searches a list for the index provided. If the list is not indexed, numbers can be used instead (starting with 0). Normally, the lookup filter can be used interchangeably with dot notation (using a dot between values), except in cases where the key being searched contains a special character or begins with an underscore. Once lookup notation has been used in a given tag, any subsequent keys must also use lookup notation. For example, {{ catalog_item|lookup:"variant".name }} would not work; {{ catalog_item|lookup:"variant"|lookup:"name" }} is the correct notation. | If your variable is [‘apple','banana','orange'], {{ your_variable|lookup:0 }} will render as apple |
lower | Converts a string to all lowercase | If your variable is HELLO, {{ your_variable|lower }} will render as hello |
lt | Within an if statement, compares whether a variable’s value is less than the filter’s argument. | If your_variable is 3, {% if your_variable|lt:2 %} will evaluate as false. |
lte | Within an if statement, compares whether a variable’s value is less than or equal to the filter’s argument. | If your_variable is 2, {% if your_variable|lte:2 %} will evaluate as true. |
md5_hash | Converts a value to an MD5 hash. | {{ your_variable|md5_hash }} |
missing_image | If a provided image is invalid, supplies a blank image, so no error displays. | {{ your_variable|missing_image }} |
missing_product_image | If a provided product image is blank, supplies a placeholder image. | {{ your_variable|missing_product_image }} |
multiply | Multiplies your variable by the number provided | If your variable is 10, {{ your_variable|multiply:7 }} will render as 70.0 |
percentize | Converts a number to a percentage, with the number of decimal places specified in the argument. If no argument is included, 0 decimals will be shown. | If your variable is .25, {{ your_variable|percentize }} will render as 25% and {{ your_variable|percentize:2 }} will render as 25.00% |
remainder | Returns the remainder of a variable divided by an argument. | If your variable is 5, {{ your_variable|remainder:2 }} will render as 1.0 |
round_down | Rounds a number down to the nearest whole number. Optionally, you may specify the number of digits to round down to. | If your variable is 2.912, {{ your_variable|round_down }} will return 2.0, and {{ your_variable|round_down:2 }} will return 2.91 |
round_up | Rounds a number up to the nearest whole number. Optionally, you may specify the number of digits to round up to. | If your variable is 2.912, {{ your_variable|round_up }} will return 3.0, and {{ your_variable|round_up:2 }} will return 2.92 |
sha_1 | Converts a value to an SHA-1 hash. | {{ your_variable|sha_1 }} |
sha_256 | Converts a value to an SHA-256 hash. | {{ your_variable|sha_256 }} |
slice | Can be applied to a list or string. If applied to a list, it provides the list items specified. If applied to a string, it provides the characters specified. | If your variable is hello world: {{ your_variable|slice:':5' }} renders as hello {{ your_variable|slice:'3:8' }} renders as lo wo {{ your_variable|slice:'8:' }} renders as rld |
split | Splits a string based on a specific character and returns a list. | {{ your_variable|split:',' }} If your variable contains the string apple, orange, banana, the output will be: ['apple', ' orange', ' banana'] |
sum_list | Sums all the values of a list, if the list contains numbers. | If your variable is [1,2,3,4,5], {{ your_variable|sum_list }} would render as 15.0 |
title | Converts a string to title case. | If your variable is hello world, {{ your_variable|title }} will render as Hello World |
trim_slash | Removed a trailing slash in a URL. | If your variable is "www.klaviyo.com\ ", {{ your_variable|trim_slash }} will render as "www.klaviyo.com " |
upper | Converts a string to uppercase. | If your variable is hello, {{ your_variable|upper }} will render as HELLO |
urldecode | Converts a URL encoded string to a normal string | {{ your_variable|urldecode }} |
This glossary is not exhaustive; review the full list of Django’s built-in filters.
Additional resources
Updated almost 2 years ago