Skip to main content
All CollectionsContentJinja reference
Cart and SmartBlock layout functions
Cart and SmartBlock layout functions

Jinja functions available inside a Cart or SmartBlock layout.

Updated over 9 months ago

Before you start

Things you need to know:

  • The information in this article is best suited for advanced users with some HTML knowledge.
    For an introduction to the use of Jinja in Cart layouts specifically, see Cart layout editing using Jinja.

  • This article lists the most common filters used with Fresh Relevance content. An exhaustive list is available if you need further information.


Jinja filters

Jinja filters can be used to perform a number of useful tasks, for example, formatting text that is output.

Some commonly useful filters include:

Convert text to lower case

{{ product.n|lower }}<!--Product Name-->

Convert text to title case

{{ product.n|title }}<!--Product Name-->

Escape text to make it safe for use in HTML

{{ product.n|escape}}<!--Product Name-->

Limit the maximum number of items looped through in an array

For example, limit the maximum number of products shown in a browse abandonment email.

{% for product in products|limit(4) %}{{ product.n }}{% endfor %}

Sort a list by a particular field

For example, sort products from highest to lowest price. Sorts ascending by default, specify reverse=True to sort descending.

{% for product in products|sort(attribute='uv',reverse=True) %}{{ product.n }}{% endfor %}

Combine with a limit filter:

{% for product in products|sort(attribute='uv',reverse=True)|limit(3) %}{{ product.n }}{% endfor %}

Trim whitespace from the start or end of text

{{ product.n|trim}}<!--Product Name-->

Extract a specific range of characters from a string

In a cart layout:

{{ product.n[0:4] }}

In a SmartBlock layout:

{{ product.n.substring(0,4) }}

Both of the above examples display the first four characters of the product name field.

Split a delimited string into an array of strings

In a Cart layout:

{% set myString = 'A||B||C' %} {{ myString.split('||') }} Output: ['A','B','C']

In a SmartBlock layout or SmartBlock filter:

{% set myString = 'A||B||C' %} {{ myString|split('||') }} Output: ['A','B','C']

Each item of the array can then be accessed in a {% for %} loop. Alternatively, further Jinja filters can be applied to the array.

Join an array of strings into a delimited string

In a Cart layout, SmartBlock layout or SmartBlock filter:

{% set myArray = ['A','B','C'] %} {{ myArray|join('||') }} Output: 'A||B||C'

This is useful for gathering product field values such as categories into a string and injecting into a Recommendations SmartBlock.

Format a currency value, with a default currency symbol of £, to two decimal places

{{ product.up|format_currency('£',2)}}<!--Product Price-->

The default currency symbol is only used if no symbol can be extracted from a text value, or if the input is a number. The default currency can be a symbol, or a supported currency code

Examples

    "$4.00"|format_currency("GBP") => "$4.00"
"4.00"|format_currency("GBP") => "£4.00"
4|format_currency("GBP") => "£4.00"
4|format_currency("USD") => "$4.00"
4|format_currency("$") => "$4.00"

Format a currency value, with a default currency symbol derived from the currency code USD, to two decimal places

{{ product.up|format_currency('USD',2)}}<!--Product Price-->

Format a currency value, with a default currency symbol obtained from the product, to two decimal places

{{ product.up|format_currency(product.curr,2)}}<!--Product Price-->

Currently supported ISO 4217 codes are:

ISO 4217 Code

Symbol

AED

د.إ

ARS

$

AUD

$

BGN

лв

BRL

R$

BYR

Br

CAD

$

CHF

CHF

CLP

$

CNY

¥

COP

$

CRC

CZK

DKK

kr

EUR

GBP

£

GTQ

Q

HKD

HK$

HUF

Ft

IDR

Rp

INR

ISK

kr

JPY

¥

KRW

MKD

ден

MXN

$

MYR

MYR

NOK

kr

NZD

$

PLN

RON

lei

RSD

РСД

RUB

руб

SAR

SEK

kr

SGD

$

THB

฿

TRY

TWD

NT$

USD

$

ZAR

R

Format a currency value, with a default currency symbol of £, to three decimal places

{{ product.up|format_currency('£',3)}}<!--Product Price-->

Format a currency value, with a default currency symbol of £, to two decimal places, with the symbol before the value

{{ product.up|format_currency('£',2,1)}}<!--Product Price-->

Format a currency value using the product currency, to two decimal places, with the symbol before the value and a space in-between

{{ product.uv|format_currency(product.curr,2,1, currency_separator=' ')}}<!--Product Price-->

Format a currency value, with a default currency symbol of £, to two decimal places, with the symbol after the value

{{ product.up|format_currency('£',2,0)}}<!--Product Price-->

Format a currency value, with a default currency symbol of £, to two decimal places, with the symbol after the value, using decimal separator ‘,’

{{ product.up|format_currency('£',2,0,',')}}<!--Product Price-->

Format a currency value, with a default currency symbol of £, to two decimal places, with the symbol before the value, using decimal separator ‘,’ and thousands separator ‘.’

{{ product.up|format_currency('£',2,1,',','.')}}<!--Product Price-->

Format a currency value using the product currency, with the symbol after the value and a space in-between, using decimal separator ‘,’ and thousands separator ‘.’

{{ product.uv|format_currency(product.curr,2,0,decimal_separator=',',thousands='.', currency_separator=' ')}}<!--Product Price-->

Format a currency value using the product currency, with the symbol before the value and a space in-between, using decimal separator ‘,’ and thousands separator ‘.’

{{ product.uv|format_currency(product.curr,2,1,decimal_separator='',thousands='.', currency_separator=' ') + ' '}}<!--Product Price-->

Format a date in ISO8601 format

{{ product.opt.start_date|date }} Output: 2014-01-01

Format a date in ISO8601 format with time in 24h format

{{ product.opt.start_date|datetime }} Output: 2014-01-01 18:35

Prettily format a date in a custom format

            {{ product.opt.start_date|prettydate }}
{{ product.opt.start_date|prettydate({"month": "short", "year": "short"}) }}
{{ product.opt.start_date|prettydate({"nth_date": true}) }}
Output: 1 July 2015
Output: 1 Jul 15
Output: 1st July 2015

Format a DateTime in W3C format

{{ signal.fdt | datetime_w3c }} Formats the datetime in w3c format, e.g. '2018-02-22T13:23:03.123221+00:00'. This format only available in Firehose field mappings. 2018-02-22T13:23:03.123221+00:00

Add analytics tracking to URLs

{{ product.u|set_tracking(tmcv='3', tmcs='3kgnzlx') }}

If the product URL was https://www.mysite.com/product/1234/ , the resulting link might then look like:

<a href="https://www.mysite.com/product/1234/?tmcv=3&tmcs=3kgnzlx" />

Add system and Google Analytics tracking to URLs

{{ product.u|set_ga_tracking(utm_campaign='fr-cart-1', utm_medium='email', utm_source='fr') }}

If the product URL was https://www.mysite.com/product/1234/ , the resulting link might then look like:

<a href="https://www.mysite.com/product/1234/?utm_campaign=fr-cart-1&utm_medium=email&utm_source=fr&tmty=b&tmti=1&tmcv=3&tmtk=n8ogq5j&tmcs=hq6c15k" />

The query params starting tm are used by Fresh Relevance to help accurately attribute purchases and other goals to triggered messages and identify the visitor when they click on a link in a trigger.

Ensure system and Google Analytics tracking are appended to the end of existing URLs

set_ga_tracking works for most links, but may re-order any existing query collection parameters for the link the function is applied to. If your website requires the existing parameters to appear first, you can append the GA tracking parameters to the end of the URL using the get_ga_tracking function:

{{ product.u }}{{ get_ga_tracking( utm_campaign=ga_campaign_code, utm_medium='email', utm_source='fr' ) }}

This function returns only the new system and GA tracking codes to be added. For example, the above call to get_ga_tracking returns something like this:

utm_campaign=fr-cart-1&tmcv=1&tmcs=mdpn6d0&tmty=b&utm_source=fr&utm_medium=email&tmti=1

Add a query string parameter to a URL

{{ product.u|set_query_parameter('utm_campaign', 'campaign123') }}

If, in this example, the product URL is http://www.example.com/products?id=12345, the output would be http://www.example.com/products?id=12345&utm_campaign=campaign123.

Add a query string parameter to a URL without URLEncoding it

{{ product.u|set_query_parameter('mailid', '{~mailID~}', false) }}

There is an optional parameter to both set_query_parameter and set_query_parameters which allows you to specify that any added parameters are not to be URL encoded. This is useful if you need to add in a merge code that is replaced by the ESP, for example, to merge in an ID.

If, in this example, the product URL is http://www.example.com/products?id=12345, the output would be http://www.example.com/products?id=12345&mailid={~mailID~}.

This won't add the system campaign parameters, so attribution to triggered messages may not work correctly. It's normally better to use set_ga_tracking.

Add multiple query string parameters to a URL

{{ product.u|set_query_parameters({'utm_campaign': 'campaign123', 'other': 'value'}) }}

If, in this example, the product URL is http://www.example.com/products?id=12345, the output would be http://www.example.com/products?id=12345&utm_campaign=campaign123&other=value.

This won't add the system campaign parameters, so attribution to triggered messages may not work correctly. It's normally better to use set_ga_tracking.

Decide if regular prices should be shown for a cart

{% set show_column = cart|should_show_regular_prices %}

This method looks at the cart and decides if it is sensible to show a regular price column. It returns true if all of the products have a unit price (up) less than the regular unit price (rup). You can then use the variable to show an extra column: {% if show_column %}{{ product.rup }}

Get a count of the total number of items in the cart

{% set item_count = cart|get_cart_quantity %}

Check if a product has a tag value (category) in a given list of category IDs

{% set is_in_category = product|is_in_categories(['photography', 'computers']) %}

This is set to True if the product belongs to either photography or cameras. Otherwise, it’s False.

Check if a product has all categories in a given list of tag values (category IDs)

{% set is_in_category = product|is_in_categories(['photography', 'lenses'], True) %}

This is set to True if the product belongs to both the photography and lenses categories. Otherwise, it‘s False.

Check if a product belongs to none of the categories in a given list of tag values (category IDs)

{% set is_in_category = product|is_not_in_categories(['photography', 'lenses']) %}

This is set to False if the product belongs to either the photography or lenses categories. Otherwise, it‘s True.

Get a count of the number of products that belong to a given list of tag values (category IDs)

{% set prods_in_categories = products|products_in_categories(['photography', 'lenses']) %}

This is set to the number of products that match either photography or lenses, to only return products that match both photography and lenses, and a true parameter on the end.

Get a count of the number of products that have the specified attribute matching one of the values provided

{% set prods_in_attribute = products|products_match('sku',['test_camera', 'test_lense']) %}

This is set to the number of products that have an SKU of either test_camera, or test_lense. This can be used for extra and optional product data by simply adding ex. or opt. at the start.

Get a list of all categories from the products, separated by the defined separator

{% set carted_categories = products|get_categories('||') %}

This is set to a string of all categories in the cart, separated by the parameter you define.

If you don’t define a separator, then it separates using a comma.

Get a list of all Product IDs from the products, separated by the defined separator

{% set carted_product_ids = products|get_prids('||') %}

This is set to a string of all product IDs in the cart, separated by the parameter you define.

If you don’t define a separator, then it separates using a comma.

Get a list of all the attribute values from the products, separated by the defined separator

{% set carted_skus = products|get_attributes('sku','||') %}

This is set to a string of all the values of the attribute defined, in this case SKU, in the cart, separated by the parameter you define.

If you don’t define a separator, then it separates using a comma.


Use data for the current product(s) on the page

The first product is exposed under {{ currentProduct }}, and the complete list of products is exposed as a list: {{ currentProducts }}.

Use the product price

{{ currentProduct.uv }}

Use product extra data

For example brand (if captured):

{{ currentProduct.ex.brand }}

Use product stock

If captured.

{{ currentProduct.stock }}

Format and sanitize tag value (Category ID)

{{ 'SoMe! cateGory '|catid }}

Output: some-category

This method allows you to slugify a tag value (category ID).

Format and sanitize tag value (Category ID) and add a tag group

{{ 'SoMe !cateGory '|catid('Some Group') }} 
OR
{{ 'Some GrouP:SoMe !cateGory '|catid }}

Output: 'some-group:some-category'

This method allows you to slugify a category ID and add a tag group.

Format and sanitize tag value (Category ID) in bulk

{{ ['SoMe !cateGory', 'some Group:Some Category',]|catid('Some Group') }}

Output: ['some-group:some-category', 'some-group:some-category']

This method allows you to format and sanitize multiple tag values (category IDs), also allows you to add a tag value (category) to any or all of the inputs.

Replace tag group

{{ 'Some Group:SoMe! cateGory'|catid('Different Group') }}

Output: 'different-group:some-category'

Replaces tag group, and slugifys output.

Get tag values (Category) from product

For: product.cat = [{'gid': 'shoe-size', 'n': '11' },{'gid': 'shoe-size', 'n': '14'}] {{ product|getCategoryValueFromProduct('shoe-size') }}}

Output: [11, 14]

Retrieves an array of values from tags (categories) that match the given gid.

Returns an empty array if no matches are found.

Filter tag values (Category) by tag (group name)

For: product.cat = [{'gid': 'shoe-size', 'n': '11' },{'gid': 'shoe-size', 'n': '14'}] {% set example = product.cat|filterGroup('Shoe Size')%}{{example[0].n}}

Output: '11'

Filters categories by group name and returns an array of matching categories.

Prefix merged in values

Allows you to prefix merged in values, for example with a tag group name. Useful in a Recommendations SmartBlock tag value (Category) filter.

{% set merges.shoe_size = 5||7 %}  
For: {{ merges.shoe_size|prefixvalues('shoe-size:') }}

Output: shoe-size:5||shoe-size:7

Exclude Categories

For a given product or list of product, exclude categories by tag value (category name - parameter 1), or by group name (parameter 2)

By tag value (Category):

For tag values (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'}  {{ currentProduct|excludeCategories('toys-and-games')|joinCategories('||') }} 

Output: 'brand:marvel'

By tag group:

For tag values (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'}  {{ currentProduct|excludeCategories(null,'brand')|joinCategories('||') }} 

Output: 'toys-and-games'

Using multiple tags or tag values:

For tag values (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Books','id':'books'},{'n':'Shoes','id':'shoes'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'},{'n':'Boys','id':'gender:boys','name':'Boys','groupname':'gender','gid':'gender'}  {{ currentProduct|excludeCategories(['toys-and-games','books'],['brand','gender'])|joinCategories('||') }} 

Output: 'shoes'

Only Tag Values (Categories)

For a given product or list of products, only return tag values (categories) by name (parameter 1), or by tag (group) name (parameter 2)

By tag value (Category):

For tag values (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'}  {{ currentProduct|onlyCategories('toys-and-games')|joinCategories('||') }} 

Output: 'toys-and-games'

By tag group:

For tags (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'}  {{ currentProduct|onlyCategories(null,'brand')|joinCategories('||') }} 

Output: 'brand:marvel'

Using multiple tags or tag values:

For tag values (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Books','id':'books'},{'n':'Shoes','id':'shoes'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'},{'n':'Boys','id':'gender:boys','name':'Boys','groupname':'gender','gid':'gender'}  {{ currentProduct|onlyCategories(['toys-and-games','books'],['brand','gender'])|joinCategories('||') }} 

Output: 'toys-and-games||books||brand:marvel||gender:boys'

Join tags (Categories)

Given a list of tags (categories), return them joined by a delimiter:

For tags (categories): {'n':'Toys & Games','id':'toys-and-games'},{'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'}  {{ currentProduct|onlyCategories('toys-and-games','brand')|joinCategories('||') }} 

Output: 'toys-and-games||brand:marvel'

Get a value of a specified Category group

Single value:

For tag values (categories): {'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'},{'n':'Boys','id':'gender:boys','name':'Boys','groupname':'gender','gid':'gender'}  {{ currentProduct|getCategoryValueFromProduct('brand') }} 

Output: ['Marvel']

Multiple values:

For tag values (categories): {'gid': 'location', 'n': 'cornwall' }, {'gid': 'location', 'n': 'uk'}, {'n':'Marvel','id':'brand:marvel','name':'Marvel','groupname':'brand','gid':'brand'} {{ currentProduct|getCategoryValueFromProduct('location') }} 

Output: ['cornwall', 'uk']


Use SmartBlock metadata

Use the SmartBlock ID

For example, for merging into tracked links:

{{ meta.q.tmsb }}

Check if the SmartBlock contains at least one product from the primary data source

{% if meta and meta.primary == true %}{% endif %}

Check if the SmartBlock contains at least one product from a fallback data source

{% if meta and (meta.fallback == 2 or meta.fallback == 3) %}{% endif %}

Check if a specific product is from the primary datasource

{% if product.meta and product.meta.fallback != true %}{% endif %}

Check if a specific product is from a fallback datasource

{% if product.meta and product.meta.fallback == true %}{% endif %}

Check if a specific product is from the first fallback datasource

{% if product.meta and product.meta.fbn == 1 %}{% endif %}


Display product rating data

Output the product rating

Where captured.

{{ product.reviews.rating }}

Output the product review count

Where captured.

{{ product.reviews.ratingCount }}


Parse date

Converts any date string of a specified syntax into a JavaScript Date object

{{parseDate('Dec. 25. 2020', 'MMM. DD. YYYY')}}

Output: 'Fri Dec 25 2020 00:00:00 GMT+0000 (GMT)'

Tokens show how the date string is formatted:

Token

Represents

D

Day: 1, 2, 3

DD

Day: 01, 02, 03

Do

Day: 1st, 2nd, 3rd

M

Month: 1, 2, 3 .. 11, 12

Mo

Month: 1st, 2nd, 3rd ... 11th, 12th

MM

Month: 01, 02 ... 11, 12

MMM

Month: Jan, Feb ... Nov, Dec

MMMM

Month: January, February ... November, December

YYYY

Year: 2016, 2017

YY

Year: 16, 17

Examples

07.03.2016 = 'DD.MM.YYYY'

March, 10th 2020 = 'MMMM, Do YYYY'


getDate

Converts any ISO formatted date string into a Date object.

{{ getDate('2017-03-09')}}

Output: '2017-03-09 00:00:00'

Can be used on various fields including product, cart and person data:

{{ getDate(product.ex.presentation_date) }}

getDate is especially useful for returning the current date and time:

{{ getDate() }}

Combining both of the above allows you to compare if a particular field is before or after today: {% if getDate(product.ex.presentation_date) > getDate() %}

The output of getDate can also be reformatted, by combining it with the date filter:

{{ getDate(product.ex.presentation_date)|date('%d %m %Y') }}

Output: '10 03 2017'


addDays

Add a specified number of days to a date by combining with getDate().

For example, add a specified number of days to today:

{{ getDate()|addDays(7) }}

Alternatively, subtract days or apply to a product date field:

{{ getDate(product.ex.presentation_date)|addDays(-7) }}


all_items_contain_field

Check if all the items in a list contain a given field. Useful for checking, for example, if all products contain review data.

{% set SortValue = "reviews.rating" if products|all_items_contain_field("reviews.rating", True) else "uv" %}

The first parameter is the field to look for. The second parameter, if set to True, checks if all the items are the same type, for example, numbers.


Get item type - type_of

Function to get the type of a particular item. Operates the same for SmartBlocks and Cart layouts.

{% set type_of_item = type_of(item) %}

This returns:

Input

Returns

A string

"string"

A number

"number"

None / null / undefined

"null"

A simple object / dictionary, e.g. {"key": "value"}

"dict"

An array / list, e.g. ["one", 2, "three"]

"array"

A date object (not a string containing a date)

"date"

Anything else

"object"


Get products from signals

This is a Jinja2 filter that extracts all the products that a person has previously browsed or abandoned, based on their signal history, from their person record. The filter returns a list of product dictionaries containing all of the product's details.

Using the default parameters:

{{ person | get_products_from_signals }}

Explicitly specifying parameters:

{{ person | get_products_from_signals(1440, 'ba', True) }}

Definitions of each parameter:

{{ person | get_products_from_signals(numMin, signalType, ignoreLastSignal) }}

Parameter

Description

Default

numMin

Maximum age of the signals to use in minutes. For example, a value of 60 means any abandons in the last hour are included. A value of -1 indicates that all available signals should be used.

-1

signalType

String that indicates the type of signal to extract products from. For example b for cart abandons, ba for browse abandons, pd for product pages viewed, and cu for custom signal.

'b'

ignoreLastSignal

Boolean indicating whether the most recent signal should be ignored.

This is useful when the most recent signal is what we are currently rendering HTML for.

False

You could then apply more filters to extract the parameters you are interested in and store it in a variable to use later:

{% set previous_prids = person | get_products_from_signals | get_prids %}


Person bestCategory

Returns the person's best tag values (categories) from best to worst, matching the supplied options.

Can currently only be used in SmartBlock layouts.

Takes the form:

{{ person|bestCategory(options) }}

Example

To return up to 10 best tag values (categories) over the last 7 days in array format, falling back to electronics if no tag values (categories) are found, and excluding gifts:

{{ person|bestCategory({days:7, max:10, format:'array', fallback:['electronics'], excludeCategories:['gifts']}) }}

For a person that had browsed two computers tag values (categories) and one gifts tag value (category), the output is: [computers,gifts] .

Full list of options:

max

Maximum number to return. Default is 1.

days

Number of days to look back. Default is 14.

type

Type of signals to consider: "t||pd||c||b||ba". Single value or array for multiple.

group

List (or single) groups to restrict filter to. || separated string or array.

fallbacks

List (or single) of categories to use if no value is found in the person. || separated string or array.

append

List (or single) categories to always append to the result.

format

Format to return data in. Defaults to array.

Other values:

feed - Returns RHS of a __f_cat= querystring param. Empty string if no result.

string - || separated string of categories.

array - array of tag values (categories).

excludeCategories

Exclude a number of tag values (categories) from output.

excludeGroups

Exclude a number of tag groups from output.


SKU-level filters

The data for each SKU's variant is stored in an object in product.variants, where the key of the object is the variant ID. This object can be processed manually but there are some Jinja filters designed to make it easier to handle SKU-level variants.

Get variant IDs from a product

The function getVariantIdsFromProduct returns an array of the variant IDs that the supplied product includes. If the supplied product does not contain any SKU-level variants, an empty list is returned.

{{ product | getVariantIdsFromProduct }}

Example result:

["SKU1001", "SKU1002"]

Get SKU-level variant from product

To get the full SKU-level variant object you need to combine the special variant data from product.variants with the base product fields.

To simplify this process there is a Jinja filter called getVariantFromProduct that you can use.

Supply this filter a product and the variant ID (vid) that you want to use and it combines all the data and returns the full variant object for that vid. If that variant doesn't exist for the given product then it returns null.

{{ product | getVariantFromProduct("SKU1001") }}

Get all SKU-level variants from product

To get an array of all of the variants of a product, use the getAllVariantsFromProduct helper.

This is the same as using the getVariantFromProduct helper to make each variant in turn.

If the product contains no variants then an empty array is returned.

{{ product | getAllVariantsFromProduct }}


SHA-1 hash

Returns a secure SHA-1 hash message digest from the value provided.

From a static text string

{{ 'Hello World'|sha1 }}

From a person's email address

{{ person.email|sha1 }}

From a person's mobile

{{ person.mobile|sha1 }}


Base64 encoding

Returns a URL-safe Base64 encoded version of the value provided.

From a static text string

{{ 'Hello World'|base64 }}

From a person's email address

{{ person.email|base64 }}

From a person's mobile

{{ person.mobile|base64 }}

To strip equals signs, pass True as the first parameter:

{{ 'Hello World'|base64(True) }}


RSA encryption

Returns an RSA encrypted version of the provided string. RSA keys must have been previously set up.

An optional role value can be passed to choose the key role to use.

The default is the content role. Currently only supported in merge fields and triggered email templates.

From a static text string

{{ 'Hello World'|rsa_encrypt }}

From a person's email address

{{ person.email|rsa_encrypt }}

From a person's mobile

{{ person.mobile|rsa_encrypt }}


Short URLs

In some situations it might be preferable to use shortened URLs in cart layouts. This is particularly useful in SMS messages.

This can be done using the shorten_url helper:

{{ product.u | shorten_url }}

This can also be combined with other functions such as the set_ga_tracking function:

{{ product.u | set_ga_tracking(utm_campaign=ga_campaign_code,utm_medium='email',utm_source='targeting') | shorten_url }}

If you don’t want the https:// protocol to be included in the short URL, you can specify this by passing false into the function:

{{ product.u | shorten_url(false) }}


Popover reporting functions

Popover reporting only works in SmartBlocks displayed on a web page that contains our script.

In order for the popover reporting to function correctly, we need to use special functions to indicate when a popover has been Shown, Dismissed and Submitted.

The functions should be used in the relevant JavaScript of the popover at the point where each action takes place.

popoverShown

$TB.popoverShown('{{ slotid }}')

popoverDismissed

$TB.popoverDismissed('{{ slotid }}')

popoverSubmitted

Where emailAddress is the submitted email address.

$TB.popoverSubmitted('{{ slotid }}', emailAddress)

You can submit additional data inside the popover in additional parameters, in the following format:

$TB.popoverSubmitted('{{ slotid }}', emailAddress, rootData, extendData)

The rootData object contains some core person fields used in Fresh Relevance. The list of fields that can be submitted is below:

Parameter

Description

e

Plain email address.

b64e

Base64-encoded email address.

rc4e

RC4-encrypted email address.

cid

Customer ID

Usually a username or user ID used on your website.

curr

Currency.

eid

External ID.

Usually to identify users in an ESP.

fn

First name.

lang

Site language.

ln

Last name.

mobile

Mobile/cell/SMS number.

perm

Permission to send emails to the person.

sbr

Site brand.

extendData contains any other data that you might want to submit with this popover.

Example popoverSubmitted signal with gender passed into extendData:

$TB.popoverSubmitted({{ slotid }}, emailAddress, {'fn': firstName, 'ln': lastName}, {'gender': customerGender})

Did this answer your question?