Personalization Using Jinja

Many features in Exponea allow the use of personalization via jinja. This enables you to personalize texts in various campaigns by calling customer attributes, catalog items, etc. Full jinja documentation can be found at and this guide summarizes some of the common examples. Some of the examples can also be found in personalization in e.g. email templates.


Jinja can be used for different use-cases, including:

  • calling user attributes and inserting these values to text. This enables to easily start the emails, etc. with customer's first name.
  • referencing catalogs, aggregates, reports or other features of Exponea in e.g. weblayers
  • creating scripts including conditions, cycles, filters, changing the format of displayed data, etc.


In Exponea, most common Jinja uses include Jinja expressions, that are called using {{ .... }} tags, and statements, that are called using {% ... %} tags

Global variables in Jinja

Campaigns and Project have variables. Variables such as ID and name can be used for personalization in campaigns.

Project variables are accessible through all campaigns (Scenario, Banner, Experiments, Tags)
{{ project['id'] }} - id of the project
{{ project['name] }} - name of the project
Scenario, Email Campaign
{{ scenario['id'] }} - id of the scenario or email campaign
{{ scenario['name'] }} - name of the scenario or email campaign
Scenario Node
{{ action['id'] }} - id of the action node in Scenario where the Jinja was executed
{{ action['name'] }} - name of the action node in Scenario where the Jinja was execute or name of the email campaign
{{ banner['id'] }} - id of the banner
{{ banner['name'] }} - name of the banner
{{ banner['variant']['id'] }} - id of the variant
{{ banner['variant']['name'] }} - name of the variant
{{ experiment['id'] }} - id of the experiment
{{ experiment['name'] }} - name of the experiment
{{ experiment['variant']['id'] }} - variant id of the experiment
{{ experiment['variant']['name'] }} - variant name of experiment
Tag manager
{{ tag['id'] }} - id of the tag
{{ tag['name'] }} - name of the tag


Expressions are used when referencing some personalization in Exponea. Basic syntax is usually {{ reference.attribute }}, however when the attribute or name consists of more words, the syntax has to be {{ reference["reference attribute"] }}. See the full list of available expressions below:

  • Customer attributes - Customer attributes will return the value that is stored in the customer profile for the specified attribute. Basic syntax is {{ customer['attribute'] }}
  • Event trigger attributes - When a scenario is triggered by an event, you can refer to its attributes using {{ event['attribute'] }}. Please note that always the keyword "event." has to be used, not the actual name of the event.
  • Webhook response - Basic syntax is {{ webhook['data'] }} or {{ webhook["JSON object key"] }}
  • Metrics - Referenced by {{ metrics["metric ID"] }}
  • Reports - It is possible to return a value from a report based on rows and columns. The syntax is {{ report_value_by_key("Report ID", "row value", "column value", metric order) }} . If you don't have columns or rows, you can skip the value. Metrics start counting from 0, and when you don't input any value, it will get first metric by default.
  • Catalog - A product from catalog can be retrieved by {{ catalogs["catalog name"].item_by_id(product_id) }}. To retrieve multiple products at once use {{ catalogs["catalog name"].items_by_id(list_of_ids) }}. Product attributes are then referenced by {{ item["catalog attribute]" }}. Please note that for this to work, you need to define item first e.g {{ set item = catalogs["Products"].item_by_id(1) }}
  • Catalog item - Product attributes are referenced by {{ item["catalog attribute]" }}. Please note that for this to work, you need to define item first e.g {{ set item = catalogs["catalog name"].item_by_id(product_id) }} or see below in statements.
  • Recommendation - Recommendations can be referenced by {{ recommendations("recommendation ID", number_of _products ) }} which will return list of products.
    To display recommended items you can loop through the returned array. Example: {%- set items = recommendations('0a1b2c3d4e5f6g7h8i9j0k', 5) %}
  • Recommendation items - Referenced by {{ item["catalog attribute]" }}. Please note that for this to work, you need to define "item" first, please see below in statements
  • Surveys -Referenced by {{ survey["survey name"] }}. This will generate a hyperlink
  • Unsubscribe link - Is generated by {{ }}. This will bring customers to the unsubscribe page where they can unsubscribe from separate campaign groups. In case the consent framework is not turn on, the link is referenced by {{ email.unsubscribe }}.
  • View in browser - Link that will display the email in the browser is generated by {{ email.view }}.
  • Other than that, it is possible to output some variables that were defined previously {{ variable }}
  • It is possible to use Math operators as well, such as +,-,*,/, however, the expression has to be within one tag, such as {{ 1+1 }}


Jinja references for metrics and reports are cached for 5 minutes before recalculated again by different customers.


Statements in Jinja are operators that can work with data in multiple ways. It allows you to, for example:

  • use conditions with following syntax (If, else if, else) {% if condition %}value{% elif condition2 %}value2{% else %}value3{% endif %} This will enable you to have e.g. call back values if someone has empty attribute.
  • use cycles, enabling you to repeat an action several times. This is useful when working with list attributes or JSONs. Syntax is {% for variable in array %} action {% endfor %}
  • using variables using {% set variable = value %}, which is used when referencing a catalog item.

It is also possible to modify the output of the statement using filters that are defined after pipe | separator. Below are possible uses of the  filters

  • first, last, length
  • lower, upper
  • trim
  • json, from_json
  • from_timestamp('%y-%m-%d')
  • hash
  • b64encode, b64decode, urldecode, urlencode, hexencode, hexdecode
  • round(value, precision=0, method='common')
    • common rounds either up or down
    • ceil always rounds up
    • floor always rounds down

These filters enable you to e.g. set an ID to lowercase email every time, ensuring that you will not generate multiple IDs (which are case sensitive) when customer decides to identify once with lowercase email and once with uppercase.

Technical Expressions

These expressions are more technical, however - they may still be useful when using Jinja.

  • sent_timestamp - unix timestamp of when the action was executed (eg email/sms sent time) {{sent_timestamp | from_timestamp }}
  • api_base_url - returns a URL to path in API
  • public_base_url - returns a URL to public app based resource
  • random_bytes - returns a random generated byte string with specifiable length (with default of 16 bytes) - {{ random_bytes() | hexencode }} or {{ random_bytes(256) | b64encode }}

Use case examples

Visit our article Useful jinja snippets to learn about practical examples.

Updated 4 months ago

Personalization Using Jinja

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.

We rely on cookies

to optimize our communication and to enhance your customer experience. By clicking on the Accept and Close button, you agree to the collection of cookies. You can also adjust your preferences by clicking on Manage Preferences. For more information please see our Privacy policy.

Manage cookies
Accept & close

Cookies preferences

Accept & close