> ## Documentation Index
> Fetch the complete documentation index at: https://developers.hubspot.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

---
id: e20f1d7c-fc1c-41e2-9330-caa6b9d6464e
---

# HubL filters

> HubL filter list and examples for HubSpot CMS developers.

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 delimiters. Some filters have additional parameters 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 should 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.

<Warning>
  **Please note:**

  You can apply HubL filters to [personalization tokens](https://knowledge.hubspot.com/marketing-email/use-personalization-tokens), such as contact and company tokens, on HubSpot CMS and blog pages, but <u>not</u> in emails.
</Warning>

## abs

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_number = -53 %}
    {{ my_number|abs }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    53
    ```
  </Tab>
</Tabs>

## add

Adds a numeric value to another numeric value. This filter functions the same as the [+ operator](/cms/reference/hubl/operators-and-expression-tests#math). The parameter in parentheses is the addend that you are combining with your initial numeric value.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_num = 40 %}
    {{ my_num|add(13) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    53
    ```
  </Tab>
</Tabs>

## 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`.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content|attr("absolute_url") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    https://developers.hubspot.com/docs/cms/hubl/filters
    ```
  </Tab>
</Tabs>

| Parameter        | Description                         |
| ---------------- | ----------------------------------- |
| `attribute_name` | Specifies which attribute to print. |

## batch

Groups items within a sequence.

In the example below, there is a 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).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set rows = ["apples", "oranges", "pears", "grapes", "blueberries"] %}

    <table>
    {% for row in rows|batch(3, " ") %}
    <tr>
    {% for column in row %}
    <td>{{ column }}</td>
    {% endfor %}
    </tr>
    {% endfor %}
    </table>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <table>
    <tbody>
    <tr>
    <td>apples</td>
    <td>oranges</td>
    <td>pears</td>
    </tr>
    <tr>
    <td>grapes</td>
    <td>blueberries</td>
    <td>&nbsp;</td>
    </tr>
    </tbody>
    </table>
    ```
  </Tab>
</Tabs>

| Parameter   | Type   | Description                                                      |
| ----------- | ------ | ---------------------------------------------------------------- |
| `linecount` | Number | The number of items to include in the batch.                     |
| `fill_with` | String | Specifies what to include in order to fill up any missing items. |

## between\_times

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

<Warning>
  **Please note:**

  You should use this filter <u>only</u> with variables that return a date. Starting September 30, 2024, this filter will no longer return the current date when a null value is passed. After that date, a null value in the filter will return September 30, 2024.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% 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") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    6
    ```
  </Tab>
</Tabs>

| Parameter  | Type            | Description                                                                                                                                                                                       |
| ---------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `end`      | datetime object | The ending datetime object.                                                                                                                                                                       |
| `timeunit` | String          | Valid time units are `nanos` , `micros` , `millis` , `seconds` , `minutes` , `hours` , `half_days` , `days` , `weeks` , `months` , `years` , `decades` , `centuries` , `millennia` , and `eras` . |

## bool

Converts a text string value to a boolean.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% if "true"|bool == true %}hello world{% endif %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    hello world
    ```
  </Tab>
</Tabs>

## capitalize

Capitalizes the first letter of a variable value. The first character will be uppercase, all others letters will be lowercased. Subsequent words separated by spaces or hyphens will not have their first letter uppercased.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set sentence = "the first letter of a sentence should always be capitalized." %}
    {{ sentence|capitalize }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    The first letter of a sentence should always be capitalized.
    ```
  </Tab>
</Tabs>

## center

Centers text within a given field length using whitespace. 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 this filter being applied to a variable in a pre tag, so the whitespace isn't stripped out.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    <pre>
    {% set var = "string to center" %}
    before{{ var|center(80) }}after
    </pre>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <pre>
    before                                string to center                                after
    </pre>
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                               |
| --------- | ------ | --------------------------------------------------------- |
| `width`   | Number | Specifies the length of whitespace to center the text in. |

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_color = "#FFFFFF" %}
    {{ my_color|convert_rgb }}
    {% set my_color2="#000000" %}
    <div style="background: rgba({{ my_color2|convert_rgb }}, .5)"></div>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    255, 255, 255

    <div style="background: rgba(0, 0, 0, .5)"></div>
    ```
  </Tab>
</Tabs>

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_string = "Hello world." %}
    {{ my_string|cut(" world") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Hello.
    ```
  </Tab>
</Tabs>

| Parameter           | Type   | Description                                    |
| ------------------- | ------ | ---------------------------------------------- |
| `characters_to_cut` | String | The part of the string that should be removed. |

## datetimeformat (deprecated)

<Warning>
  **Please note:**

  This filter has been [deprecated](/cms/versions-deprecations/deprecated/hubl/filters-functions#datetimeformat). Instead, use the [format\_datetime](#format_datetime) filter, which has a more standardized syntax.
</Warning>

## 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 applies the filter to an empty string, which is not undefined, but it prints a message due to the second parameter.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ my_variable|default("my_variable is not defined") }}
    {{ ""|default("the string was empty", true) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    my_variable is not defined the string was empty
    ```
  </Tab>
</Tabs>

| Parameter       | Type    | Description                                                                                                                       |
| --------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `default_value` | String  | The value to return if the variable is undefined. If the variable is defined, the value of the variable will be returned instead. |
| `truthy`        | Boolean | Set to `true` to use with variables which evaluate to `false`.                                                                    |

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% for item in contact|dictsort(false, "value") %}
    {{item}}
    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    A sorted contact dictionary
    ```
  </Tab>
</Tabs>

| Parameter        | Type                 | Description                                     |
| ---------------- | -------------------- | ----------------------------------------------- |
| `case_sensitive` | Boolean              | Determines if sorting is case sensitive.        |
| `sort_by`        | `"key"` \| `"value"` | Determines whether to sort by `key` or `value`. |

## difference

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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ [1, 2, 3]|difference([2, 3, 4, 5]) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [1]
    ```
  </Tab>
</Tabs>

| Parameter | Type  | Description                                                                          |
| --------- | ----- | ------------------------------------------------------------------------------------ |
| `list`    | Array | The second list to compare to for use in finding differences from the original list. |

## divide

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set numerator = 106 %}
    {{ numerator|divide(2) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    53
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                           |
| --------- | ------ | ------------------------------------- |
| `divisor` | Number | The number to divide the variable by. |

## divisible

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set num = 10 %}
    {% if num|divisible(2) %}
    The number is divisible by 2
    {% endif %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    The number is divisible by 2
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                                  |
| --------- | ------ | ------------------------------------------------------------ |
| `divisor` | Number | The number to use when evaluating if the value is divisible. |

## escape\_html

Escapes the content of an HTML input. Accepts a string and converts the characters `&`, `<`, `>`, `‘`, `”`, and `escape_jinjava` into HTML-safe sequences. Use this filter for HubL variables that are used in HTML but should not allow any HTML.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "<div>This markup is printed as text</div>" %}
    {{ escape_string|escape_html }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div>This markup is printed as text</div>
    ```
  </Tab>
</Tabs>

## escape\_attr

Escapes the content of an HTML attribute input. Accepts a string and converts the characters `&`, `<`, `‘`, `”`, and `escape_jinjava` into HTML-safe sequences. Use this filter for HubL variables that are being added to HTML attributes.

Note that when escaping values of attributes that accept URLs, such as `href`, you should use the `escape_url` filter instead.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "This <br> markup is printed as text" %}
    <img src="test.com/imageurl" alt="{{escape_string|escape_attr}}">
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <img src="test.com/imageurl" alt="This <br> markup is printed as text" />
    ```
  </Tab>
</Tabs>

## escape\_jinjava

Converts the characters `{` and `}` in strings to Jinjava-safe sequences. Use this filter if you need to display text that might contain such characters in Jinjava.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "{{This markup is printed as text}}" %}
    {{ escape_string|escape_jinjava }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    {{This markup is printed as text}}
    ```
  </Tab>
</Tabs>

## escape\_js

Escapes strings, including `escape_jinjava`, so that they can be safely inserted into a JavaScript variable declaration. Use this filter for HubL variables that are used inside HTML script elements.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "\tThey said 'This string can safely be inserted into JavaScript.'" %}
    {{ escape_string|escape_js }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    \tThey said \x27This string can safely be inserted into JavaScript.\x27
    ```
  </Tab>
</Tabs>

## escape\_url

Escapes the content of a URL input, enforcing specified protocols, sanitizing invalid and dangerous characters, and encoding HTML entities. Use this filter for HubL variables that are used within HTML attributes that should be valid URLs.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "https://developers.hubspot.com/docs/examplepath/with space/<html>" %}
    <a href="{{ escape_string|escape_url }}">Click me</a>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <a href="https://developers.hubspot.com/docs/examplepath/with%20space/%3Chtml%3E">Click me</a>
    ```
  </Tab>
</Tabs>

## escapejson

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "<script>alert('oh no!')</script>" %}
    {% require_js position="head" %}
    <script data-search_input-config="config_{{ name }}" type="application/json">
    {
    "autosuggest_results_message": "{{ escape_string|escapejson }}"
    }
    </script>
    {% end_require_js %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <script
    data-search_input-config="config_widget_1234567"
    type="application/json"
    >
    {
    "autosuggest_results_message": "<script>alert('oh no!')<\/script>"
    }
    </script>
    ```
  </Tab>
</Tabs>

## filesizeformat

Formats a number value into a human-readable file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). By default, decimal prefixes are used (e.g., MB and GB), but you can set the `binary` parameter to `true` to use binary prefixes such as Mebi (MiB) and Gibi (GiB).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set bytes = 10000 %}
    {{ bytes|filesizeformat(binary=true) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    9.8 KiB
    ```
  </Tab>
</Tabs>

| Parameter | Type    | Description                                                                    |
| --------- | ------- | ------------------------------------------------------------------------------ |
| `binary`  | Boolean | If set to `true`, binary prefixes are used, such as Mebi (MiB) and Gibi (GiB). |

## first

Returns the first item in a sequence.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_sequence = ["Item 1", "Item 2", "Item 3"] %}
    {{ my_sequence|first }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Item 1
    ```
  </Tab>
</Tabs>

## float

Converts a 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_text="25" %}
    {{ my_text|float + 17 }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    42.0
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                       |
| --------- | ------ | ------------------------------------------------- |
| `default` | Number | Integer to return if the conversion doesn't work. |

## forceescape

Strictly enforces 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "<div>This markup is printed as text</div>" %}
    {{ escape_string|forceescape }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div>This markup is printed as text</div>
    ```
  </Tab>
</Tabs>

## format

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ "Hi %s %s"|format(contact.firstname, contact.lastname) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Hi Monty Python
    ```
  </Tab>
</Tabs>

## format\_currency (deprecated)

<Warning>
  **Please note:**

  This filter has been [deprecated](/cms/versions-deprecations/deprecated/hubl/filters-functions). Instead, use the [format\_currency\_value](#format_currency_value) filter.
</Warning>

## format\_currency\_value

Formats a given number as a currency based on portal's default currency and locale passed in as a parameter. Replaces the deprecated [format\_currency filter](/cms/versions-deprecations/deprecated/hubl/filters-functions#format_currency).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ 100 | format_currency_value(locale='en-GB', currency='EUR', maxDecimalDigits=6, minDecimalDigits=1) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    €100.0
    ```
  </Tab>
</Tabs>

| Parameter          | Type   | Description                                                                                                                                                                                                              |
| ------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `locale`           | String | [The Java local Language tag](https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html). The default is the page's `locale.Format : ISO639LanguageCodeInLowercase-ISO3166CountryCodeInUppercase`. |
| `currency`         | String | the [alphabetic ISO 4217 code](https://en.wikipedia.org/wiki/ISO_4217) of the currency, default is the portals default currency. Numeric codes are not accepted.                                                         |
| `minDecimalDigits` | Number | The minimum number of decimal digits to include in the output. Defaults to the currency's default number of decimal digits.                                                                                              |
| `maxDecimalDigits` | Number | The maximum number of decimal digits to include in the output. Defaults to the currency's default number of decimal digits.                                                                                              |

## format\_date

Formats the date component of a date object.

<Warning>
  **Please note:**

  You should use this filter <u>only</u> with variables that return a date. Starting September 30, 2024, this filter will no longer return the current date when a null value is passed. After that date, a null value in the filter will return September 30, 2024.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content.publish_date | format_date('long') }}
    {{ content.publish_date | format_date('yyyy.MMMM.dd') }}
    {{ content.publish_date | format_date('medium', 'America/New_York', 'de-DE') }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    November 28, 2022 02022.November.28 28.11.2022
    ```
  </Tab>
</Tabs>

| Parameter  | Type                                                              | Description                                                                                                                                     |
| ---------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| custom pattern | The format to use. Can be a custom pattern following [Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns).     |
| `timeZone` | String                                                            | The time zone of the output date in [IANA TZDB format](https://data.iana.org/time-zones/tzdb/).                                                 |
| `locale`   | String                                                            | The locale to use for locale-aware formats. See [list of supported locales](https://www.oracle.com/java/technologies/javase/java8locales.html). |

## format\_datetime

Formats both the date and time components of a date object. This filter replaces the deprecated [datetimeformat](/cms/versions-deprecations/deprecated/hubl/filters-functions#datetimeformat-nbsp-) filter. By default, returns a datetime in the UTC-00:00 time zone.

<Warning>
  **Please note:**

  You should use this filter <u>only</u> with variables that return a date. Starting September 30, 2024, this filter will no longer return the current date when a null value is passed. After that date, a null value in the filter will return September 30, 2024.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content.publish_date | format_datetime('medium', 'America/New_York', 'de-DE') }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    12/31/69 7:00 PM
    ```
  </Tab>
</Tabs>

| Parameter  | Type                                                              | Description                                                                                                                                                                                                                                                                                                      |
| ---------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| custom pattern | The format to use. Can be one a custom pattern following [Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns). When using `long` or `full`, timestamp will include a Z to denote zero offset UTC time (i.e., `2:23:00 PM Z`). To remove the Z designator, specify a `timeZone`. |
| `timeZone` | String                                                            | The time zone of the output date in [IANA TZDB format](https://data.iana.org/time-zones/tzdb/). By default, returns UTC time.                                                                                                                                                                                    |
| `locale`   | String                                                            | The locale to use for locale-aware formats. See [list of supported locales](https://www.oracle.com/java/technologies/javase/java8locales.html).                                                                                                                                                                  |

## format\_number

Formats a given number based on a specified locale. Includes a second parameter that sets the maximum decimal precision.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ 1000|format_number('en-US') }}
    {{ 1000.333|format_number('fr') }}
    {{ 1000.333|format_number('en-US', 2) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    1,000
    1 000,333
    1,000.33
    ```
  </Tab>
</Tabs>

| Parameter          | Type   | Description                                                                                                                            |
| ------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| `locale`           | String | The locale to use for formatting. See [list of supported locales](https://www.oracle.com/java/technologies/javase/java8locales.html).  |
| `maxDecimalDigits` | Number | The maximum number of decimal digits to include in the output. By default, will use the number of decimal digits from the input value. |

## format\_time

Formats the time component of a date object.

<Warning>
  **Please note:**

  You should use this filter <u>only</u> with variables that return a date. Starting September 30, 2024, this filter will no longer return the current date when a null value is passed. After that date, a null value in the filter will return September 30, 2024.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content.updated | format_time('long') }}
    {{ content.updated | format_time('hh:mm a') }}
    {{ content.updated | format_time('medium', 'America/New_York', 'de-DE') }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    3:25:06 PM Z 03:25 PM 10:25:44
    ```
  </Tab>
</Tabs>

| Parameter  | Type                                                              | Description                                                                                                                                                                                                                                                                                                      |
| ---------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `format`   | `'short'` \| `'medium'` \| `'long'` \| `'full'` \| custom pattern | The format to use. Can be one a custom pattern following [Unicode LDML](https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns). When using `long` or `full`, timestamp will include a Z to denote zero offset UTC time (i.e., `2:23:00 PM Z`). To remove the Z designator, specify a `timeZone`. |
| `timeZone` | String                                                            | The time zone of the output date in [IANA TZDB format](https://data.iana.org/time-zones/tzdb/). By default, returns UTC time.                                                                                                                                                                                    |
| `locale`   | String                                                            | The locale to use for locale-aware formats. See [list of supported locales](https://www.oracle.com/java/technologies/javase/java8locales.html).                                                                                                                                                                  |

## fromjson

Converts a JSON string to an object.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set obj ='{ "name":"Brian","role":"Owner" }' %}
    {{ obj|fromjson }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    {role=Owner, name=Brian}
    ```
  </Tab>
</Tabs>

## geo\_distance

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    <!-- 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
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    861.1655563461395 MI
    ```
  </Tab>
</Tabs>

## groupby

Groups a sequence of objects by a common attribute. The parameter sets the common attribute to group by.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    <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>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <ul>
    <li>
    Blog author 1
    <ul>
    <li>Post by Blog author 1</li>
    <li></li>
    <li>Post by Blog author 1</li>
    <li></li>
    <li>Post by Blog author 1</li>
    <li></li>
    </ul>
    </li>
    <li>
    Blog author 2
    <ul>
    <li>Post by Blog author 2</li>
    <li></li>
    <li>Post by Blog author 2</li>
    <li></li>
    <li>Post by Blog author 2</li>
    <li></li>
    </ul>
    </li>
    <li>
    Blog author 3
    <ul>
    <li>Post by Blog author 3</li>
    <li></li>
    <li>Post by Blog author 3</li>
    <li></li>
    <li>Post by Blog author 3</li>
    <li></li>
    </ul>
    </li>
    </ul>
    ```
  </Tab>
</Tabs>

| Parameter   | Description                |
| ----------- | -------------------------- |
| `attribute` | The attribute to group by. |

## indent

Indents text within a given field length using whitespace. This filter is not recommended or particularly useful because 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 an `indent` 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    <pre>
    {% set var = "string to indent" %}
    {{ var|indent(2, true) }}
    </pre>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    string to indent
    ```
  </Tab>
</Tabs>

| Parameter      | Type    | Description                                          |
| -------------- | ------- | ---------------------------------------------------- |
| `width`        | Number  | The amount of whitespace to be applied.              |
| `indent-first` | Boolean | When set to `true`, the first line will be indented. |

## int

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set string="25" %}
    {{ string|int + 17 }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    42
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                       |
| --------- | ------ | ------------------------------------------------- |
| `default` | Number | Integer to return if the conversion doesn't work. |

## intersect

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ [1, 2, 3]|intersect([2, 3, 4, 5]) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [2, 3]
    ```
  </Tab>
</Tabs>

| Parameter | Type  | Description                                                                                        |
| --------- | ----- | -------------------------------------------------------------------------------------------------- |
| `list`    | Array | The second list to compare to for use in finding where the list intersects with the original list. |

## ipaddr

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set ip = "1.0.0.1" %}
    {% if ip|ipaddr %}
    The string is a valid IP address
    {% endif %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    The string is a valid IP address
    ```
  </Tab>
</Tabs>

## join

Returns 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_list = [1, 2, 3] %}
    {% set sep = "---" %}
    {{ my_list|join }}
    {{ my_list|join("|") }}
    {{ my_list|join(sep) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    123 1|2|3 1---2---3
    ```
  </Tab>
</Tabs>

| Parameter   | Type          | Description                                      |
| ----------- | ------------- | ------------------------------------------------ |
| `delimiter` | String        | The delimiter to use when concatenating strings. |
| `attribute` | HubL Variable | Attribute of value to join in an object.         |

## last

Returns the last item of a sequence.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_sequence = ["Item 1", "Item 2", "Item 3"] %}
    {{ my_sequence|last }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Item 3
    ```
  </Tab>
</Tabs>

## length

Returns the number of items of a sequence or mapping.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set services = ["Web design", "SEO", "Inbound Marketing", "PPC"] %}
    {{ services|length }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    4
    ```
  </Tab>
</Tabs>

## list

Converts values into a list. Strings will be returned as separate characters unless contained in square bracket sequence delimiters `[ ]`.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set one = 1 %}
    {% set two = 2 %}
    {% set three = "three" %}
    {% set four = ["four"] %}
    {% set list_num = one|list + two|list + three|list + four|list %}
    {{ list_num }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [1, 2, t, h, r, e, e, four]
    ```
  </Tab>
</Tabs>

## log

Calculates the natural logarithm of a number.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ 10|log }}
    {{ 65536|log(2) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    2.302585092994046 16.0
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                              |
| --------- | ------ | ---------------------------------------- |
| `base`    | Number | The base to use for the log calculation. |

## lower

Converts all letters in a value to lowercase.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set text="Text to MAKE LowercaSe" %}
    {{ text|lower }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    text to make lowercase
    ```
  </Tab>
</Tabs>

## map

Applies a filter on a sequence of objects or looks up an attribute. This is useful when dealing with a list of objects where you're 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {# Usage 1 #}
    Apply a filter to a sequence:
    {% set seq = ["item1", "item2", "item3"] %}
    {{ seq|map("upper") }}

    {# Usage 2 #}
    Look up an attribute:
    {{ content|map("currentState")}}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Apply a filter to a sequence: [ITEM1, ITEM2, ITEM3]
    Look up an attribute: [DRAFT]
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                 |
| --------- | ------ | ------------------------------------------- |
| `filter`  | String | Filter to apply to the sequence of objects. |

## md5

Calculates the [md5 hash](https://en.wikipedia.org/wiki/MD5) of the given object.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content.absolute_url|md5 }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    923adb4ce05a4c6342c04c80be88d15e
    ```
  </Tab>
</Tabs>

## minus\_time

Subtracts an amount of time from a datetime object.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
    {{ date }}
    {{ date|minus_time(2, "months") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    2018-07-14 14:31:30 2018-05-14 14:31:30
    ```
  </Tab>
</Tabs>

| Parameter  | Type   | Description                                                                                                                                                                                       |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `diff`     | Number | Amount to subtract.                                                                                                                                                                               |
| `timeunit` | String | Valid time units are `nanos` , `micros` , `millis` , `seconds` , `minutes` , `hours` , `half_days` , `days` , `weeks` , `months` , `years` , `decades` , `centuries` , `millennia` , and `eras` . |

## multiply

Multiplies a value with a number. Functions the same as the [\* operator](/cms/reference/hubl/operators-and-expression-tests).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set n = 20 %}
    {{ n|multiply(3) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    60
    ```
  </Tab>
</Tabs>

## plus\_time

Adds an amount of time to a datetime object.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set date = "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ") %}
    {{ date }}
    {{ date|plus_time(5, "days") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    2018-07-14 14:31:30 2018-07-19 14:31:30
    ```
  </Tab>
</Tabs>

| Parameter  | Type   | Description                                                                                                                                                                                       |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `diff`     | Number | Amount to add.                                                                                                                                                                                    |
| `timeunit` | String | Valid time units are `nanos` , `micros` , `millis` , `seconds` , `minutes` , `hours` , `half_days` , `days` , `weeks` , `months` , `years` , `decades` , `centuries` , `millennia` , and `eras` . |

## pprint

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set this_var ="Variable that I want to debug" %}
    {{ this_var|pprint }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    (String: Variable that I want to debug)
    ```
  </Tab>
</Tabs>

## random

Return a random item from the sequence.

<Warning>
  **Please note:**

  When using this filter, the page will be [prerendered](/cms/best-practices/testing-staging-performance/prerendering) periodically rather than every time the page content is updated. This means that the filtered content will <u>not</u> be updated on every page reload.

  This may not be an issue for certain types of content, such as displaying a random list of blog posts. However, if you need content to change randomly on every page load, you should instead use JavaScript to randomize the content client-side.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% for content in contents|random %}
    <div class="post-item">Post item markup</div>
    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="post-item">Random post</div>
    ```
  </Tab>
</Tabs>

## 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.

Learn more about [RE2 regex syntax](https://github.com/google/re2/wiki/Syntax).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ "contact-us-2"|regex_replace("[^a-zA-Z]", "") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    contactus
    ```
  </Tab>
</Tabs>

## reject

Filters a sequence of objects by applying an [expression test](/cms/reference/hubl/operators-and-expression-tests) to the object and rejecting the ones with the test succeeding.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %}
    {{ some_numbers|reject("even") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [13, 3, 5, 17]
    ```
  </Tab>
</Tabs>

| Parameter  | Type   | Description                                                                                                                    |
| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `exp_text` | String | The name of the [expression test](/cms/reference/hubl/operators-and-expression-tests#expression-tests) to apply to the object. |

## rejectattr

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% 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 %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="post-item">Post with no featured image</div>
    <div class="post-item">Post with no featured image</div>
    <div class="post-item">Post with no featured image</div>
    ```
  </Tab>
</Tabs>

| Parameter        | Type   | Description                                                                                                                    |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `attribute_name` | String | Specifies the attribute to select. You can access nested attributes using dot notation.                                        |
| `exp_test`       | String | The name of the [expression test](/cms/reference/hubl/operators-and-expression-tests#expression-tests) to apply to the object. |

## render

Renders strings containing HubL early so that the output can be passed into other filters.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ personalization_token("contact.lastname", "default value")|render|lower }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    mclaren
    ```
  </Tab>
</Tabs>

## replace

Replaces all instances of a substring with a new one.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% if topic %}
    <h3>Posts about {{ page_meta.html_title|replace("Blog | ", "") }}</h3>
    {% endif %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <h3>Posts about topic name</h3>
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                                 |
| --------- | ------ | ----------------------------------------------------------- |
| `old`     | String | The substring that should be replaced.                      |
| `new`     | String | Replacement string.                                         |
| `count`   | Number | If provided, only the first count occurrences are replaced. |

## reverse

Reverses the object or return an iterator the iterates over it the other way round. To reverse a list use [.reverse()](/cms/reference/hubl/functions#reverse)

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}
    {% for num in nums|reverse %}
    {{ num }}
    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    10 9 8 7 6 5 4 3 2 1
    ```
  </Tab>
</Tabs>

## root

Calculates the square root of a value.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ 16|root }}
    {{ 625|root(4) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    4 5
    ```
  </Tab>
</Tabs>

| Parameter  | Type   | Description                              |
| ---------- | ------ | ---------------------------------------- |
| `nth_root` | Number | The nth root to use for the calculation. |

## round

Rounds a number to a given precision.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ 52.5|round }}
    {{ 52.5|round(0, "floor") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    53 52
    ```
  </Tab>
</Tabs>

| Parameter         | Type                                          | Description                                                                                                      |
| ----------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `precision`       | Number                                        | Specifies the precision of the rounding.                                                                         |
| `rounding_method` | `'common'` (default) \| `'ceil'` \| `'floor'` | Options include `common` round either up or down (default); `ceil` always rounds up; `floor` always rounds down. |

## safe

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ content.post_list_content|safe }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <p>HTML post content that is not escaped.</p>
    ```
  </Tab>
</Tabs>

## sanitize\_html

Sanitizes the content of an HTML input for the output of rich text content. Accepts a string, then strips HTML tags that are not allowed. Use this filter for HubL variables that are used in HTML that should allow safe HTML.

You can include the following parameters to allow specific types of HTML tags: `FORMATTING`, `BLOCKS`, `STYLES`, `LINKS`, `TABLES`, `IMAGES`. For example, `sanitize_html(IMAGES)`.

Using `sanitize_html` will include all parameters in the filter.

You can also include a `STRIP` parameter to strip <u>all</u> HTML. All content is run through `escape_jinjava` as well to prevent nested interpretation.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "This <br> <div>markup is <img src='test.com/image'> <span>printed</span> as text.</div>" %}
    {{ escape_string|sanitize_html("IMAGES") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    This  markup is <img src="test.com/image"> printed as text.</div>
    ```
  </Tab>
</Tabs>

## select

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set some_numbers = [10, 12, 13, 3, 5, 17, 22] %}
    {{ some_numbers|select("even") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [10, 12, 22]
    ```
  </Tab>
</Tabs>

| Parameter  | Type   | Description                                 |
| ---------- | ------ | ------------------------------------------- |
| `exp_text` | String | The expression test to apply to the object. |

## selectattr

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% 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 %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="post-item">
    <div class="hs-featured-image-wrapper">
    <a
    href="http://blog.hubspot.com/marketing/how-to-get-a-job"
    title=""
    class="hs-featured-image-link"
    >
    <img
    src="//cdn2.hubspot.net/hub/53/hubfs/00-Blog-Related_Images/landing-a-job-featured-image.png?t=1431452322770&width=761"
    class="hs-featured-image"
    />
    </a>
    </div>
    Post with featured image
    </div>
    ```
  </Tab>
</Tabs>

| Parameter        | Type   | Description                                                                                                                    |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `attribute_name` | String | The attribute to test for. You can access nested attributes using dot notation.                                                |
| `exp_test`       | String | The name of the [expression test](/cms/reference/hubl/operators-and-expression-tests#expression-tests) to apply to the object. |
| `val`            | String | Value to test against.                                                                                                         |

## shuffle

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

<Warning>
  **Please note:**

  When using this filter, the page will be [prerendered](/cms/best-practices/testing-staging-performance/prerendering) periodically rather than every time the page content is updated. This means that the filtered content will <u>not</u> be updated on every page reload.

  This may not be an issue for certain types of content, such as displaying a random list of blog posts. However, if you need content to change randomly on every page load, you should instead use JavaScript to randomize the content client-side.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% for content in contents|shuffle %}
    <div class="post-item">Markup of each post</div>
    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="post-item">Markup of each post 5</div>
    <div class="post-item">Markup of each post 3</div>
    <div class="post-item">Markup of each post 1</div>
    <div class="post-item">Markup of each post 2</div>
    <div class="post-item">Markup of each post 4</div>
    ```
  </Tab>
</Tabs>

## slice

Slices an iterator and returns 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% 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>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="columwrapper">
    <ul class="column-1">
    <li>laptops</li>
    <li>tablets</li>
    <li>smartphones</li>
    </ul>

    <ul class="column-2">
    <li>smart watches</li>
    <li>TVs</li>
    <li></li>
    </ul>
    </div>
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                   |
| --------- | ------ | --------------------------------------------- |
| `slices`  | Number | How many items will be sliced.                |
| `filler`  | String | Specifies characters to fill in empty slices. |

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_posts = blog_recent_posts("default", limit=5) %}

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

    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    A post<br />
    B post<br />
    C post<br />
    D post<br />
    E post<br />
    ```
  </Tab>
</Tabs>

| Parameter        | Type    | Description                                     |
| ---------------- | ------- | ----------------------------------------------- |
| `reverse`        | Boolean | Set to `true` to reverse the sort order.        |
| `case_sensitive` | Boolean | Set to `true` to make sorting case sensitive.   |
| `attribute`      | String  | Attribute to sort by. Omit when sorting a list. |

## 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 four names.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set string_to_split = "Mark; Irving; Helly; Dylan; Milchick; Harmony;" %}
    {% set names = string_to_split|split(";", 4) %}
    <ul>
    {% for name in names %}
    <li>{{ name }}</li>
    {% endfor %}
    </ul>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <ul>
    <li>Mark</li>
    <li>Irving</li>
    <li>Helly</li>
    <li>Dylan; Milchick; Harmony;</li>
    </ul>
    ```
  </Tab>
</Tabs>

| Parameter               | Type   | Description                                                                                       |
| ----------------------- | ------ | ------------------------------------------------------------------------------------------------- |
| `character_to_split_by` | String | Specifies the separator to split the variable by.                                                 |
| `number_of_splits`      | Number | Determines how many times the variable should be split. Any remaining items would remain grouped. |

## 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).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set number_to_string = 45 %}
    {{ number_to_string|string|pprint }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    (String: 45)
    ```
  </Tab>
</Tabs>

## striptags

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set some_html = "<div><strong>Some text</strong></div>" %}
    {{ some_html|striptags }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    some text
    ```
  </Tab>
</Tabs>

## strtodate

Converts a date string and date format to a date object.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ '3/3/21'|strtodate('M/d/yy') }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    2021-03-03 00:00:00
    ```
  </Tab>
</Tabs>

| Parameter    | Type   | Description                                                                                          |
| ------------ | ------ | ---------------------------------------------------------------------------------------------------- |
| `dateFormat` | String | The [date format](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) to use. |

## strtotime

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ "2018-07-14T14:31:30+0530"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    1531558890000
    ```
  </Tab>
</Tabs>

| Parameter        | Type   | Description                                                                                                   |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------- |
| `datetimeFormat` | String | The [Date and time format](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) to use. |

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    // Simple sum
    {% set sum_this = [1, 2, 3, 4, 5] %}
    {{ sum_this|sum }}

    // Sum of attribute
    {% set items = [15, 10] %}
    {% set dict_var = [{"name": "Item1", "price": "20"}, {"name": "Item2", "price": "10"}] %}
    Total: {{ dict_var|sum(attribute="price") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    15 Total: 30
    ```
  </Tab>
</Tabs>

| Parameter           | Type   | Description                                                 |
| ------------------- | ------ | ----------------------------------------------------------- |
| `attribute`         | String | Attribute to sum.                                           |
| `return_if_nothing` | String | Value to return if there is nothing in the variable to sum. |

## symmetric\_difference

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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ [1, 2, 3]|symmetric_difference([2, 3, 4, 5]) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [1, 4, 5]
    ```
  </Tab>
</Tabs>

| Parameter | Type  | Description                                                                                       |
| --------- | ----- | ------------------------------------------------------------------------------------------------- |
| `list`    | Array | The second list to compare to for use in finding the symmetric difference with the original list. |

## title

Returns a title case version of the value (i.e., words will start with uppercase letters but all remaining characters are lowercase).

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_title="my title should be title case" %}
    {{ my_title|title }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    My Title Should Be Title Case
    ```
  </Tab>
</Tabs>

## tojson

Writes an object as a JSON string.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% for content in contents %}
    {{ content.blog_post_author|tojson }}
    {% endfor %}
    ```
  </Tab>

  <Tab title="Output">
    ```json theme={null}
    {
      "portalId": 1234567,
      "id": 12312253109,
      "created": 1566413741989,
      "updated": 1566414012799,
      "deletedAt": 0,
      "fullName": "Sample User",
      "email": "sampleUser@example.com",
      "userId": null,
      "username": null,
      "slug": "sample-user",
      "jsonBody": {
        "avatar": "https://app.hubspot.com/settings/avatar/109d6874a0cb066c1c7263ac5df6ce7a",
        "bio": "Sample Bio",
        "facebook": "",
        "linkedin": "",
        "twitter": "",
        "website": "https://www.hubspot.com"
      },
      "bio": "Sample Bio",
      "facebook": "",
      "linkedin": "",
      "avatar": "https://app.hubspot.com/settings/avatar/109d6874a0cb066c1c7263ac5df6ce7a",
      "gravatarUrl": "https://app.hubspot.com/settings/avatar/108bb5ac667ded34796271437dfe8d58",
      "twitterUsername": "",
      "hasSocialProfiles": false,
      "website": "https://www.hubspot.com",
      "twitter": "",
      "displayName": "Sample User"
    }
    ```
  </Tab>
</Tabs>

## trim

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ " remove whitespace " }}
    {{ " remove whitespace "|trim }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    remove whitespace remove whitespace
    ```
  </Tab>
</Tabs>

## truncate

Cuts off text after a certain number of characters. The default is 255. HTML characters are included in this count.

<Warning>
  **Please note:**

  Because this filter relies on the spaces between words to shorten strings, it may not work as expected for languages without spaces between characters, such as Japanese.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ "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, ".......") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    I only want to show the first sentence. ...
    I only want to show the first sente.......
    ```
  </Tab>
</Tabs>

| Parameter              | Type    | Description                                                                                   |
| ---------------------- | ------- | --------------------------------------------------------------------------------------------- |
| `number_of_characters` | Number  | Number of characters to allow before truncating the text. Default is 255.                     |
| `breakword`            | Boolean | If `true`, the filter will cut the text at length. If `false`, it will discard the last word. |
| `end`                  | String  | Override the default '...' trailing characters after the truncation.                          |

## truncatehtml

Truncates a given string, respecting HTML markup (i.e. will properly close all nested tags). This will prevent a tag from remaining open after truncation. HTML characters do not count towards the character total.

<Warning>
  **Please note:**

  Because this filter relies on the spaces between words to shorten strings, it may not work as expected for languages without spaces between characters, such as Japanese.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set html_text = "<p>I want to truncate this text without breaking my HTML<p>" %}
    {{ html_text|truncatehtml(28, "..." , false) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <p>I want to truncate this..</p>
    ```
  </Tab>
</Tabs>

| Parameter              | Type    | Description                                                                                                                                                                                                                                 |
| ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `number_of_characters` | Number  | Number of characters to allow before truncating the text. Default is 255.                                                                                                                                                                   |
| `end`                  | String  | Override the default '...' trailing characters after the truncation.                                                                                                                                                                        |
| `breakword`            | Boolean | Boolean value. If `true`, the filter will cut the text at length. If `false` (default), it will discard the last word. If using only one of the optional parameters, use keyword arguments, such as `truncatehtml(70, breakwords = false)`. |

## unescape\_html

Converts text with HTML-encoded entities to their Unicode equivalents.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set escape_string = "me & you" %}
    {{ escape_string|unescape_html }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    me & you
    ```
  </Tab>
</Tabs>

## union

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ [1, 2, 3]|union([2, 3, 4, 5]) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [1, 2, 3, 4, 5]
    ```
  </Tab>
</Tabs>

| Parameter | Type  | Description                                      |
| --------- | ----- | ------------------------------------------------ |
| `list`    | Array | The second list to union with the original list. |

## unique

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 which attribute is used to deduplicate items in the dict.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set my_sequence = ["one", "one", "two", "three" ] %}
    {{ my_sequence|unique }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    [one, two, three]
    ```
  </Tab>
</Tabs>

| Parameter | Type   | Description                                                              |
| --------- | ------ | ------------------------------------------------------------------------ |
| `attr`    | String | Specifies the attribute that should be used when filtering a dict value. |

## unixtimestamp

Converts a datetime object into a Unix timestamp.

<Warning>
  **Please note:**

  You should use this filter <u>only</u> with variables that return a date. Starting September 30, 2024, this filter will no longer return the current date when a null value is passed. After that date, a null value in the filter will return `September 30, 2024`.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ local_dt }}
    {{ local_dt|unixtimestamp }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    2017-01-30 17:11:44 1485814304000
    ```
  </Tab>
</Tabs>

## upper

Converts all letters in a value to uppercase.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set text="text to make uppercase" %}
    {{ text|upper }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    TEXT TO MAKE UPPERCASE
    ```
  </Tab>
</Tabs>

## urlencode

Escapes and URL encodes a string using UTF-8 formatting. Accepts both dictionaries and regular strings as well as pairwise iterables.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set encode_value="Escape & URL encode this string" %}
    {{ encode_value|urlencode }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Escape+%26+URL+encode+this+string
    ```
  </Tab>
</Tabs>

## urldecode

Decodes encoded URL strings back to the original URL. Accepts both dictionaries and regular strings as well as pairwise iterables.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set decode_value="Escape+%26+URL+decode+this+string" %}
    {{ decode_value|urldecode }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    Escape & URL decode this string
    ```
  </Tab>
</Tabs>

## 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {{ "http://hubspot.com/"|urlize }}
    {{ "http://hubspot.com/"|urlize(10,true) }}
    {{ "http://hubspot.com/"|urlize("",true) }}
    {{ "http://hubspot.com/"|urlize("",false,target="_blank") }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <a href="https://developers.hubspot.com/docs//hubspot.com/">http://hubspot.com/</a>
    <a href="https://developers.hubspot.com/docs//hubspot.com/" rel="nofollow">http://...</a>
    <a href="https://developers.hubspot.com/docs//hubspot.com/" rel="nofollow">http://hubspot.com/</a>
    <a href="https://developers.hubspot.com/docs//hubspot.com/" target="_blank">http://hubspot.com/</a>
    ```
  </Tab>
</Tabs>

| Parameter         | Type    | Description                                                  |
| ----------------- | ------- | ------------------------------------------------------------ |
| `shorten_text`    | Number  | Integer that will shorten the urls to desired number.        |
| `no_follow`       | Boolean | When set to `true`, the link will include `rel="no follow"`. |
| `target="_blank"` | String  | Specifies whether the link will open in a new tab.           |

## wordcount

Counts the number of words in a string.

<Warning>
  If the string contains HTML, use the `striptags` filter to get an accurate count.
</Warning>

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {%  set count_words = "Count the number of words in this variable"  %}
    {{ count_words|wordcount }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    8
    ```
  </Tab>
</Tabs>

## wordwrap

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

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% 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) }}
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    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.
    ```
  </Tab>
</Tabs>

| Parameter         | Description                                  |
| ----------------- | -------------------------------------------- |
| `character_count` | Number of characters to wrap the content at. |

## xmlattr

Creates 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.

<Tabs sync={false}>
  <Tab title="HubL">
    ```jinja theme={null}
    {% set html_attributes = {"class": "bold", "id": "sidebar"} %}
    <div {{ html_attributes|xmlattr }}></div>
    ```
  </Tab>

  <Tab title="Output">
    ```html theme={null}
    <div class="bold" id="sidebar"></div>
    ```
  </Tab>
</Tabs>

| Parameter   | Type    | Description                                        |
| ----------- | ------- | -------------------------------------------------- |
| `autospace` | Boolean | Set to `true` to add a space in front of the item. |
