HubL Supported Filters

Last updated:

Filters affect the ultimate output of your HubL. They can be applied to various HubL statements and expressions to alter the template markup outputted by the server.

The basic syntax of a filter is |filtername. The filter is added directly following the statement or the expression, within its delimeters. Some filters have additional parmeters that can be added in parentheses. The basic syntax of a filter with a string, a number, and a boolean parameters is: |filtername('stringParameter', 10, true). Notice that string parameters shoud be written in quotes. Also note that HubL filters have an alias that can be used to serve the same purpose as the primary filter.

The following article contains all of the supported HubL filters.

Please note that using filters on any personalization variables (such as but not limited to contacts, company, and deal variables) is not currently supported for email in HubSpot due to how emails are rendered. Filters can be applied to these properties on HubSpot CMS page and blog templates.

abs

Gets the absolute value of a number. You can use this filter to ensure that a number is positive.

{% set my_number = -53 %} 
{{ my_number|abs }}

add

Adds a numeric value to another numeric value. This filter functions the same as the + operator. The parameter in parentheses is the addend that you are combining with your initial numeric value.

{% set my_num = 40 %} 
{{ my_num|add(13) }}

attr

Renders the attribute of a dictionary. This filter is the equivalent of printing a variable that exists within a dictionary, such as content.absolute_url.

Parameter Description
attribute_name
REQUIRED

Specifies which attribute to print

{{ content|attr('absolute_url') }} 

batch

A batch filter groups up items within a sequence.

Parameter Description
linecount
Required

The number of items to include in the batch

fill_with
Optional

Specifies what to include in order to fill up any missing items

In the example below, there is variable containing a sequence of types of fruits. The batch filter is applied to a loop that iterates through the sequence. The nested loop runs three times to print 3 types of fruit per row, before the outer loop runs again. Notice in the final output that since there are only 5 types of fruit, the final item is replaced by a &nbsp (the second parameter).

{% set rows = ['apples', 'oranges', 'pears', 'grapes', 'blueberries'] %}

<table>
{% for row in rows|batch(3, '&nbsp;') %}
   <tr>
    {% for column in row %}
        <td>{{ column }}</td>
    {% endfor %}
    </tr> 
{% endfor %}
</table>

between_times

Calculates the time between two datetime objects in a specified time unit.

Parameter Description
end
Required

The ending datetime object

timeunit
Required

Valid time units are nanos , micros , millis , seconds , minutes , hours , half_days , days , weeks , months , years , decades , centuries , millennia , and eras .

{% set begin = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
{% set end = "2018-07-20T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
{{ begin|between_times(end, 'days') }}

bool

Converts a text string value to a boolean.

{% if "true"|bool == true %}hello world{% endif %}

capitalize

Capitalize the first letter of a variable value. The first character will be uppercase, all others letters will retain their original case.

{% set sentence = "the first letter of a sentence should always be capitalized." %} 
{{ sentence|capitalize }}

center

The center filter uses whitespace to center text within a given field length. This filter is not recommended or particularly useful since HubSpot's HTML compiler will automatically strip out the white space; however, it is included here for the sake of comprehensiveness.

Parameter Description
width
Required

Specifies the length of whitespace to center the text in.

The example below shows a center filter being applied to a variable in a pre tag, so the whitespace isn't stripped out.

<pre>
{% set var = "string to center" %}
before{{ var|center(80) }}after
</pre>

convert_rgb

Converts a HEX value to an RGB string. This is useful if you need to convert color variables to RGB to be used with a RGBA CSS declaration. In the example below, the value set by a color module is converted to an RGB value and used in an RGBA CSS declaration.

{% set my_color = "#FFFFFF" %}
{{ my_color|convert_rgb }}

{% color "my_color" color="#000000", export_to_template_context=True %}
<div style="background: rgba({{ widget_data.my_color.color|convert_rgb }}, .5)"></div>

cut

Removes a string from a value. This filter can be used to match and cut out a specific part of a string. The parameter specifies the part of the string that should be removed. The example below removes the space and the word world from the original variable value.

Parameter Description
characters_to_cut
Required

The part of the string that should be removed.

{% set my_string = "Hello world." %} 
{{ my_string|cut(' world') }}

datetimeformat

Formats a date object. By default, HubSpot date variables print as timestamps. The datetimeformat filter is used to convert that timestamp into a legible date and/or time. The filter's parameters, listed in the table below, dictate how the time variable ultimately renders. 

A null date input to the filter assumes the current date and time.

An optional second parameter can be used to specify a timezone. The timezone must be in a supported Java 8 format.

Parameter Description
format
Required

Directive format for the datetime object. See the directive table under the example for values. 

timezone
Optional

Specifies a timezone. Must be in a supported Java 8 format.

{{ content.updated|datetimeformat('%B %e, %Y') }}
{{ content.publish_date|datetimeformat('%B %e, %Y %l %p') }} 
{{ content.publish_date|datetimeformat('%B %e, %Y %l %p', 'America/Los_Angeles') }}
datetime formatting
Directive Example Description
%a
Sun, Mon, ..., Sat (en_US);So, Mo, ..., Sa (de_DE)Weekday as locale’s abbreviated name.
%A
Sunday, Monday, ..., Saturday (en_US);Sonntag, Montag, ..., Samstag (de_DE)

Weekday as locale’s full name.

%w
1, 2, ..., 7

Weekday as a decimal number, where 1 is Sunday and 7 is Saturday.

NOTE: This differs from python day numbers which start at 0.

%d
01, 02, ..., 31

Day of the month as a zero-padded decimal number.

%e
1, 2, ..., 31

Day of the month as a decimal number, without padding.

%b
Jan, Feb, ..., Dec (en_US);Jan, Feb, ..., Dez (de_DE)

Month as locale’s abbreviated name.

%B
January, February, ..., December (en_US);Januar, Februar, ..., Dezember (de_DE)

Month as locale’s full name.

%OB
1月, 2月, ..., 12月 (ja)

Get the nominative version of the months name.

%m
01, 02, ..., 12

Month as a zero-padded decimal number.

%y
00, 01, ..., 99

Year without century as a zero-padded decimal number.

%Y
1970, 1988, 2001, 2013

Year with century as a decimal number.

%H
00, 01, ..., 23

Hour (24-hour clock) as a zero-padded decimal number.

%I
01, 02, ..., 12

Hour (12-hour clock) as a zero-padded decimal number.

%k
0, 1, ..., 24

The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.

%l
1, 2, ..., 12

(note this is a lower case L) The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.

%p
AM, PM (en_US);am, pm (de_DE)

Locale’s equivalent of either AM or PM.

%M
00, 01, ..., 59

Minute as a zero-padded decimal number.

%S
00, 01, ..., 59

Second as a zero-padded decimal number.

%f
000000, 000001, ..., 999999

Microsecond as a decimal number, zero-padded on the left.

%z
(empty), +0000, -0400, +1030

UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).

%Z
(empty), UTC, EST, CST

Time zone name (empty string if the object is naive).

%j
001, 002, ..., 366

Day of the year as a zero-padded decimal number.

%U
00, 01, ..., 53

Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.

%W
00, 01, ..., 53

Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0.

%c
Tue Aug 16 21:30:00 1988 (en_US);Di 16 Aug 21:30:00 1988 (de_DE)

Locale’s appropriate date and time representation.

%x
08/16/88 (None);08/16/1988 (en_US);16.08.1988 (de_DE)

Locale’s appropriate date representation.

%X
21:30:00 (en_US);21:30:00 (de_DE)

Locale’s appropriate time representation.

%%
%

A literal '%' character.

default

If the value is undefined it will return the first parameter, otherwise the value of the variable will be printed. If you want to use default with variables that evaluate to false, you have to set the second parameter to true. The first example below would print the message if the variable is not defined. The second example applied the filter to an empty string, which is not undefined, but it prints a message due to the second parameter.

Parameter Description
default_variable
Required

Value to return if the variable is undefined. If the variable is defined, the value of the variable will be returned instead.

boolean
Optional

Returns the default_value if the variable is an empty string

{{ my_variable|default('my_variable is not defined') }} 
{{ ''|default('the string was empty', true) }}

dictsort

Sort a dict and yield (key, value) pairs. Dictionaries are unsorted by default, but you can print a dictionary, sorted by key or value. The first parameter is a boolean to determine, whether or not the sorting is case sensitive. The second parameter determines whether to sort the dict by key or value. The example below prints a sorted contact dictionary, with all the known details about the contact.

Parameter Description
case_sensitive
Required

Determines if sorting is case sensitive

sort_by
Required

Determines whether to sort by key or value

{% for item in contact|dictsort(false, 'value') %}
    {{item}}
{% endfor %}

difference

This filter returns the difference of two sets or lists. The list returned from the filter contains all unique elements that are in the first list but not the second.

Parameter Description
list
Required

The second list to compare to for use in finding differences from the original list.

{{ [1, 2, 3]|difference([2, 3, 4, 5]) }}

divide

Divide the current value by a divisor. The parameter passed is the divisor. This filter is an alternative to the / operator.

Parameter Description
divisor
Required

The number to divide the variable by.

{% set numerator = 106 %}
{{ numerator|divide(2) }}

divisible

An alternative to the divisibleby expression test, the filter divisible will evaluate to true if the value is divisible by the given number.

Parameter Description
divisor
Required

The number to use when evaluating if the value is divisible.

{% set num = 10 %}
{% if num|divisible(2) %}
The number is divisble by 2
{% endif %}

escape

Convert the characters &, <, >, ‘, and ” in string to HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. Marks return value as markup string.

{% set escape_string = "<div>This markup is printed as text</div>" %} 
{{ escape_string|escape }}

escape_jinjava

Converts the characters { and } in string s to Jinjava-safe sequences. Use this filter if you need to display text that might contain such characters in Jinjava. Marks return value as markup string.

{% set escape_string = "{{This markup is printed as text}}" %}
{{ escape_string|escape_jinjava }}

escapejs

Escapes strings so that they can be safely inserted into a JavaScript variable declaration.

{% set escape_string = "\tThey said 'This string can safely be inserted into JavaScript.'" %}
{{ escape_string|escapejs }}

escapejson

Escapes strings so that they can be used as JSON values.

{% set your_string = '\tTesting a \"quote for the week\"'
{{ your_string|escapejson }}

filesizeformat

Format the value like a ‘human-readable’ file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the parameter is set to True the binary prefixes are used (Mebi, Gibi).

Parameter Description
boolean
Optional

If set to true, binary prefixes are used such as Mebi & Gibi.

{% set bytes = 100000 %} 
{{ bytes|filesizeformat }}

first

Returns the first item in a sequence.

{% set my_sequence = ['Item 1', 'Item 2', 'Item 3'] %} 
{{ my_sequence|first }}

float

Convert the value into a floating point number. If the conversion doesn’t work it will return 0.0. You can override this default using the first parameter.

Parameter Description
default
Optional

Integer to return if the conversion doesn't work. 

{% text "my_text" value='25', export_to_template_context=True %} 
{{ widget_data.my_text.value|float + 28 }}

forceescape

Strictly enforce HTML escaping. In HubSpot's environment there isn't really a use case for double escaping, so this is generally behaves the same as the escape filter.

{% set escape_string = "<div>This markup is printed as text</div>" %} 
{{ escape_string|forceescape }}

format

Apply Python string formatting to an object. %s can be replaced with another variable.

{{ "Hi %s %s"|format(contact.firstname, contact.lastname) }} 

format_currency

Formats a given number as a currency based on portal's default currency and locale passed in as a parameter.

Parameter Description
locale
Optional

The Java local Language tag. The default is the page's locale.Format : ISO639LanguageCodeInLowercase-ISO3166CountryCodeInUppercase

{% set price = 100 %}
{{ price|format_currency("en-US") }}
{{ price|format_currency("fr-FR") }}

fromjson

Converts a JSON string to an object.

{% set obj ='{ "name":"Brian","role":"Owner" }' %}
{{ obj|fromjson }}

geo_distance

Calculates the ellipsoidal 2D distance between two points on Earth.

<!-- in the example below the HubDB Location = 42.3667, -71.1060 (Cambridge, MA) | Chicago, IL = 37.3435, -122.0344 -->
{{ row.location | geo_distance(37.3435, -122.0344, "mi") }} MI

groupby

The groupby filter groups a sequence of objects by a common attribute.The parameter sets the common attribute to group by.

Parameter Description
attribute
Required

The attribute to group by.

<ul>
{% for group in contents|groupby('blog_post_author') %}
    <li>{{ group.grouper }}
      <ul>
        {% for content in group.list %}
          <li>{{ content.name }}</li>
        {% endfor %}
      </ul>
    </li>
{% endfor %}
</ul>

indent

The indent filter uses whitespace to indent text within a given field length. This filter is not recommended or particularly useful since HubSpot's HTML compiler will automatically strip out the white space; however, it is included here for the sake of comprehensiveness. The example below shows a center filter being applied to a variable in a pre tag, so the whitespace isn't stripped out. The first parameter controls the amount of whitespace and the second boolean toggles whether to indent the first line.

Parameter Description
width
Required

The amount of whitespace to be applied.

boolean
Required

A boolean value on whether to indent the first line.

<pre>
{% set var = "string to indent" %}
{{ var|indent(2, true) }}
</pre>

int

Convert the value into an integer. If the conversion doesn’t work it will return 0. You can override this default using the first parameter.

Parameter Description
default
Required

Integer to return if the conversion doesn't work.

{% text "my_text" value='25', export_to_template_context=True %} 
{{ widget_data.my_text.value|int + 28 }}

intersect

This filter returns the intersection of two sets or lists. The list returned from the filter contains all unique elements that are contained in both lists.

Parameter Description
list
Required

The second list to compare to for use in finding where the list intersects with the original list.

{{ [1, 2, 3]|intersect([2, 3, 4, 5]) }}

ipaddr

Evaluates to true if the value is a valid IPv4 or IPv6 address.

{% set ip = '1.0.0.1' %}
{% if ip|ipaddr %}
    The string is a valid IP address
{% endif %}

join

Return a string which is the concatenation of the strings in the sequence. The separator between elements is an empty string per default, you can define it with the optional parameter. The second parameter can be used to specify an attribute to join.

Parameter Type Description
delimiter
Optional
String

The delimiter to use when concatenating strings.

attribute
Optional
HubL Variable

An attribute to use as a delimiter.

{% set my_list = [1, 2, 3] %}
{% set sep = "---" %}
{{ my_list|join }}
{{ my_list|join('|') }}
{{ my_list|join(sep) }}

last

Returns the last item of a sequence.

{% set my_sequence = ['Item 1', 'Item 2', 'Item 3'] %}
{% my_sequence|last %}

length

Return the number of items of a sequence or mapping.

{% set services = ['Web design', 'SEO', 'Inbound Marketing', 'PPC'] %} 
{{ services|length }}

list

Convert the number values into a list. If it was a string the returned list will be a list of characters. To add strings to a sequence, simply add them to the string variables to the sequence delimiters [ ].

{% set one = 1 %}
{% set two = 2 %}
{% set three = 3 %}
{% set four = ["four"] %}
{% set list_num = one|list + two|list + three|list + four|list %}
{{ list_num }}

log

Calculates the natural logarithm of a number.

Parameter Description
base
Optional

Calculate the logarithm at the nth base.

{{ 10|log }}
{{ 65536|log(2) }}

lower

Convert a value to all lowercase letters.

{{ text "text" value='Text to MAKE Lowercase', export_to_template_context=True }} 
{{ widget_data.text.value|lower }}

map

Applies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with lists of objects but you are really only interested in a certain value of it.

The basic usage is mapping on an attribute. For example, if you want to use conditional logic to check if a value is present in a particular attribute of a dict. Alternatively, you can let it invoke a filter by passing the name of the filter and the arguments afterwards.

You can use either one of these parameters listed below.
Parameter Description
attribute

Attribute to return in the sequence of objects.

filter

Filter to apply to the sequence of objects.

{% set seq = ['item1', 'item2', 'item3'] %}
{{ seq|map('upper') }}
{{ content|map('currentState')}}

md5

Calculates the md5 hash of the given object

{{ content.absolute_url|md5 }} 

minus_time

Subtracts an amount of time to a datetime object.

Parameter Description
diff
Required

Amount to subtract.

timeunit
Required

Valid time units are nanos , micros , millis , seconds , minutes , hours , half_days , days , weeks , months , years , decades , centuries , millennia , and eras .

{% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
{{ date }}
{{ date|minus_time(2, 'months') }}

mulitply

Multiplies a value with a number. Functions the same as the * operator.

{% set n = 20 %} 
{{ n|multiply(3) }}

plus_time

Adds an amount of time to a datetime object.

Parameter Description
diff
Required

Amount to add.

timeunit
Required

Valid time units are nanos , micros , millis , seconds , minutes , hours , half_days , days , weeks , months , years , decades , centuries , millennia , and eras .

{% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
{{ date }}
{{ date|plus_time(5, 'days') }}

pprint

Pretty print a variable. This prints the type of variable and other info that is useful for debugging.

{% set this_var ="Variable that I want to debug" %} 
{{ this_var|pprint }}

random

Return a random item from the sequence. The random function does NOT break caching. It is best used for scenarios where you are okay with the random item is selected when the server-side cache refreshes, not on page load. If you do need to return a random item every page load you should use javascript.

{% for content in contents|random %}
<div class="post-item">Post item markup</div>
{% endfor %}

regex_replace

Searches for a regex pattern and replaces with a sequence of characters. The first argument is a RE2-style regex pattern, the second is the replacement string.

Information on the RE2 regex syntax can be found here.

{{ "contact-us-2"|regex_replace("[^a-zA-Z]", "") }} 

reject

Filters a sequence of objects by applying an expression test to the object and rejecting the ones with the test succeeding.

Parameter Description
exp_text

The expression test to apply to the object.

{% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %} 
{{ some_numbers|reject('even') }}

rejectattr

Filters a sequence of objects by applying a test to an attribute of an object and rejecting the ones with the test succeeding. 

Parameter Description
attribute_name
Required

Specifies the attribute to select. You can access nested attributes using dot notation.

exp_test
Optional

The expression to test

val
Optional

Value to test against.

{% for content in contents|rejectattr('post_list_summary_featured_image') %}
<div class="post-item">
{% if content.post_list_summary_featured_image %}
    <div class="hs-featured-image-wrapper">
            <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
            <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
            </a>
    </div>
{% endif %}
{{ content.post_list_content|safe }}
</div>
{% endfor %}

replace

Replace all instances of a substring with a new one. 

Parameter Description
old
Required

The substring that should be replaced.

new
Required

Replacement string.

count
Optional

If provided, only the firstcount occurrences are replaced.

{% if topic %}
<h3>Posts about {{ page_meta.html_title|replace('Blog | ', '') }}</h3>
{% endif %}

reverse

Reverse the object or return an iterator the iterates over it the other way round. To reverse a list use .reverse()

{% set nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}
{% for num in nums|reverse %}
{{ num }}
{% endfor %}

root

Calculates the square root of a value.

Parameter Description
nth_root
Optional

Calculate the nth root of a number.

{{ 16|root }}
{{ 625|root(4) }}

round

Round the number to a given precision.

Parameter Description
precision
Optional

Specifies the precision of the rounding.

rounding_method
Optional

Options include common round either up or down (default); ceil always rounds up; floor always rounds down.

If you don’t specify a method common is used.

{{ 52.5|round }} 
{{ 52.5|round(0, 'floor') }}

safe

Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped.

{{ content.post_list_content|safe }} 

select

Filters a sequence of objects by applying a test to the object and only selecting the ones with the test succeeding.

Parameter Description
exp_text

The expression test to apply to the object.

{% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %} 
{{ some_numbers|select('even') }}

selectattr

Filters a sequence of objects by applying a test to an attribute of an object and only selecting the ones with the test succeeding.

Parameter Description
attribute_name
Required

Specifies the attribute to select. You can access nested attributes using dot notation.

exp_test
Optional

The expression to test

val
Optional

Value to test against.

{% for content in contents|selectattr('post_list_summary_featured_image') %}
<div class="post-item">
  {% if content.post_list_summary_featured_image %}
    <div class="hs-featured-image-wrapper">
       <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
         <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
       </a>
    </div>
  {% endif %}
{{ content.post_list_content|safe }}
</div>
{% endfor %}

shuffle

Randomizes the order of iteration through a sequence. The example below shuffles a standard blog loop.

{% for content in contents|shuffle %}
<div class="post-item">Markup of each post</div>
{% endfor %}

slice

Slice an iterator and return a list of lists containing those items. The first parameter specifies how many items will be sliced, and the second parameter specifies characters to fill in empty slices.

Parameter Description
slices
Required

How many items will be sliced.

filler
Required

Specifies characters to fill in empty slices. 

{% set items = ['laptops', 'tablets', 'smartphones', 'smart watches', 'TVs'] %}
<div class="columwrapper">
  {% for column in items|slice(3,' ') %}
    <ul class="column-{{ loop.index }}">
    {% for item in column %}
      <li>{{ item }}</li>
    {% endfor %}
    </ul>
  {% endfor %}
</div>

sort

Sorts an iterable. This filter requires all parameters to sort by an attribute in HubSpot. The first parameter is a boolean to reverse the sort order. The second parameter determines whether or not the sorting is case sensitive. And the final parameter specifies an attribute to sort by. In the example below, posts from a blog are rendered and alphabetized by name.

Parameter Description
reverse
Required

Boolean value to reverse the sort order.

case_sensitive
Required

Boolean value that determines if the sorting is case sensitive. 

attribute
Required

Attribute to sort by.

{% set my_posts = blog_recent_posts('default', limit=5) %}

{% for item in my_posts|sort(False, False, 'name') %}
{{ item.name }}<br>


{% endfor %}

split

Splits the input string into a list on the given separator. The first parameter specifies the separator to split the variable by. The second parameter determines how many times the variable should be split. Any remaining items would remained group. In the example below, a string of names is split at the ";" for the first 4 names.

Parameter Description
character_to_split_by
Required

Specifies the separator to split the variable by.

number_of_splits
Required

Determines how many times the variable should be split. Any remaining items would remain grouped.

{% set string_to_split = "Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda" %}
{% set names = string_to_split|split(';', 4) %}
<ul>
{% for name in names %}
  <li>{{ name }}</li>
{% endfor %}
</ul>

string

Converts a different variable type to a string. In the example below, a integer is converted into a string (pprint is used to confirm the change in variable type).

{% set number_to_string = 45 %} 
{{ number_to_string|string|pprint }}

striptags

Strip SGML/XML tags and replace adjacent whitespace by one space. This filter can be used to remove any HTML tags from a variable.

{% set some_html = "<div><strong>Some text</strong></div>" %} 
{{ some_html|striptags }}

strtotime

Converts a datetime string and a datetime format into a datetime object.

Parameter Description
datetimeFormat
Required

Date and time patterns.

{{ "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp }}

sum

Adds numeric values in a sequence. The first parameter can specify an optional attribute and the second parameter sets a value to return if there is nothing in the variable to sum.

Parameter Description
attribute
Optional

Attribute to sum.

return_if_nothing
Optional

Value to return if there is nothing in the variable to sum.

{% set sum_this = [1, 2, 3, 4, 5] %}
{{ sum_this|sum }}
Total: {{ items|sum(attribute='price') }}

symmetric_difference

This filter returns the symmetric difference of two sets or lists. The list returned from the filter contains all unique elements that are in the first list but not the second, or are in the second list but not the first

Parameter Description
list
Required

The second list to compare to for use in finding the symmetric difference with the original list.

{{ [1, 2, 3]|symmetric_difference([2, 3, 4, 5]) }}

title

Return a titlecased version of the value. I.e. words will start with uppercase letters, all remaining characters are lowercase.

{% text "my_title" label='Enter a title', value='My title should be titlecase', export_to_template_context=True %} 
{{ widget_data.my_title.value|title }}

tojson

Writes an object as a JSON string.

{% for content in contents %}
  {{ content.blog_post_author|tojson }}
{% endfor %}

trim

Strips leading and trailing whitespace. HubSpot already trims whitespace from markup, but this filter is documented for the sake of comprehensiveness.

{{ " remove whitespace " }} 
{{ " remove whitespace "|trim }}

truncate

Cuts off text after a certain number of characters. The default is 255. Please note that HTML characters are included in this count. The length is specified with the first parameter which defaults to 255. If the second parameter is true the filter will cut the text at length. Otherwise it will discard the last word. If the text was in fact truncated it will append an ellipsis sign ("..."). If you want a different ellipsis sign than "..." you can specify it using the third parameter.

Use this table to describe parameters / fields
Parameter Description
number_of_characters
Required

Number of characters to truncate the text by. Default is 255.

breakword
Optional

Boolean value. If true, the filter will cut the text at length. If false, it will discard the last wrod. 

end
Optional

Override the default '...' trailing characters after the truncation.

{{ "I only want to show the first sentence. Not the second."|truncate(40) }} 
{{ "I only want to show the first sentence. Not the second."|truncate(35, True, '..........') }}

truncatehtml

Truncates a given string, respecting html markup (i.e. will properly close all nested tags). This will prevent a tag from being remaining open after truncation. HTML characters do not count towards the character total. This filter has a length parameter and a truncation symbol parameter. There is a third boolean parameter that specifies whether words will be broken at length. This parameter is false by default in order to preserve the length of words.

Parameter Description
number_of_characters
Required

Number of characters to truncate the text by. Default is 255.

end
Optional

Override the default '...' trailing characters after the truncation.

breakword
Optional

Boolean value. If true, the filter will cut the text at length. If false, it will discard the last wrod. 

{% set html_text = "<p>I want to truncate this text without breaking my HTML<p>" %} 
{{ html_text|truncatehtml(28, '..' , false) }}

union

This filter returns the union of two sets or lists. The list returned from the filter contains all unique elements that are in either list.

Parameter Description
list
Required

The second list to union with the original list.

{{ [1, 2, 3]|union([2, 3, 4, 5]) }}

unique

This filter extracts a unique set from a sequence or dict of objects. When filtering a dict, such as a list of posts returned by a function, you can specify the which attribute should be used to deduplicate items in the dict.

Parameter Description
attr
Optional

Specifies the attribute that should be used when filtering a dict value

{% set my_sequence = ['one', 'one', 'two', 'three' ] %} 
{{ my_sequence|unique }}

unixtimestamp

This filter converts a datetime object into a unix timestamp.

{{ local_dt }} 
{{ local_dt|unixtimestamp }}

upper

Convert a value to all uppercase letters.

{% text "text" value='text to make uppercase', export_to_template_context=True %} 
{{ widget_data.text.value|upper }}

urlencode

Escapes a url encodes a string using UTF-8 formatting.

{% text "encode" value="Escape & URL encode this string", label="Enter slug", export_to_template_context=True %} 
{{ widget_data.encode.value|urlencode }}

urlize

Converts URLs in plain text into clickable links. If you pass the filter an additional integer it will shorten the urls to that number. The second parameter is a boolean that dictates whether the link is rel="no follow". The final parameter lets you specify whether the link will open in a new tab.

Parameter Description
shorten_text
Optional

Integer that will shorten the urls to desired number.

no_follow
Optional

Boolean value to indicate whether the link is rel="no follow".

target='_blank'
Optional

Specifies whether the link will open in a new tab.

{{ "http://hubspot.com/"|urlize }}
{{ "http://hubspot.com/"|urlize(10,true) }}
{{ "http://hubspot.com/"|urlize('',true) }}
{{ "http://hubspot.com/"|urlize('',false,target='_blank') }}

wordcount

Count the number of words in a string.

If the string contains HTML, use the striptags filter to get an accurate count.

{%  set count_words = "Count the number of words in this variable"  %} 
{{ count_words|wordcount }}

wordwrap

Causes words to wrap at a given character count. This works best in a <pre> because HubSpot strips whitespace by default.

Parameter Description
character_count
Required

Number of characters to wrap the content at.

{% set wrap_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam efficitur, ipsum non sagittis euismod, ex risus rhoncus lectus, vel maximus leo enim sit amet dui. Ut laoreet ultricies quam at fermentum." %} 
{{ wrap_text|wordwrap(10) }}

xmlattr

Create an HTML/XML attribute string, based on the items in a dict. All values that are neither none
nor undefined are automatically escaped. It automatically prepends a space in front of the item if the filter returned something unless the first parameter is false.

Parameter Description
autospace
Required

Boolean value that will automatically prepend a space in front of the item unless set to false.

{% set html_attributes = {'class': 'bold', 'id': 'sidebar'} %}
<div {{ html_attributes|xmlattr }}></div>