Using the Jinja Templating Language

Learn more about advanced Jinja templating language use cases to use in email templates.

Updated over a week ago

Send highly personalized emails to your customers with personalized elements such as customer attributes (name, email address) or product attributes (product category, name). Bluecore personalizes emails with Jinja templating language to add additional customization to content.

  • NOTE: Bluecore supports everything that's available in the Jinja templating language. We’ve also added additional custom filtering for particular use cases.

Please note that this is an advanced article requiring a technical skill set. For a more basic understanding of dynamic attributes in Bluecore, click here.

Looking for examples of how to use Jinja in subject lines? Check out this article for some of our suggested use cases.

GETTING STARTED

Before adding customer attributes to your email campaigns, be sure to review the data that’s available within your account through the Customer 360 page. You can see the product attributes available within your account through the Product Catalog page. If there is a specific attribute you’d like to use, such as customer first name, last name; please be sure this is included in your Bluecore integration.

  • TIP: Learn more about how to use Jinja in tracking parameters here.

Below are frequently used advanced Jinja syntax examples.

CUSTOMER ATTRIBUTES

Dynamic Attribute

Description

{{customer.email}}

Display customer’s email address

{{customer.attribute_name}}

Use this attribute to display any additional customer attributes that may be available within Bluecore, such as first name, gender, etc.


CAMPAIGN ATTRIBUTES

Dynamic Attribute

Description

{{campaign_name}}

Campaign Name

{{nqe.subaction}}

Campaign ID

©{{nqe.created|pretty_time('%Y')}}

©2021


DYNAMIC PRODUCT ATTRIBUTES

For the following attributes, be sure to adjust the below templated Jinja syntax to match the blocks, products, etc. within your email. For example, the dynamic attribute of {{BLOCKNAME.products.0.url}}, the BLOCKNAME should be replaced with the actual name of the block in the email.

The below attributes can be configured to display the most common value (mode) of the products or the value of the first product.

This is only a sampling of the attributes that are available for your account. Please see the Product Details Page within your account for the full list.

Dynamic Attribute

Example

{{BLOCKNAME.products|mode('category')}} or {{BLOCKNAME.products.0.category}}

Shoes

{{BLOCKNAME.products|mode('brand')}} or {{BLOCKNAME.products.0.brand}}

Nike

{{BLOCKNAME.products|mode(‘name’)}} or {{BLOCKNAME.products.0.name}}

Air Max

{{BLOCKNAME.products.0.url}}


PRICE ATTRIBUTES

We recommend using the Dynamic Product Blocks in VTE. If you must use an advanced custom code block to display product information, you can use this syntax.

Filter

Example Syntax

Example

money_format_with_commas

{{product.price|money_format_with_commas(currency="£", separator=",", decimal=".", use_cents=False)}}

Input: 242000

Output: £242,000

Money_format_with_locale_and_currency

{{product.price|money_format_with_locale_and_currency("en-US_USD_$#,##0.##")}}

Input: 1229.6789

Output: $1,229.68

Values inside the () can be customized

Advanced price conditional example

{% if product.price|float > 5 %} {{product.price|money_format}}

{% endif %}

Product prices are strings by default. Run this filter to do numerical comparisons. Please note that negatives are not supported at the beginning of a comparison.

Advanced price conditional example

{% if product.on_sale %}

Now: {{product.price|money_format}}

Original: {{product.original_price|money_format}}

{% else %}

{{product.price|money_format}}

{% endif %}

Use this if you want to display the price differently if the product is on sale.


ADVANCED MISC. JINJA FILTERS

Filter

Example Syntax

Example

Upper Case

{{BLOCKNAME.products.0.name|upper}}

Input: “Air Max”

Output: “AIR MAX”

Lower Case

{{BLOCKNAME.products.0.name|lower}}

Input: “Air Max”

Output: “air max”

Capitalize

{{BLOCKNAME.products.0.name|capitalize}}

Input: “air max”

Output: “Air max”

Title

{{BLOCKNAME.products.0.name|title}}

Input: “air max”

Output: “Air Max”

Replace

{{BLOCKNAME.products.0.name|replace("-", " ")}}

Input: air-max

Output: air max

Split

{{BLOCKNAME.products.0.name|split("-")}}

Input: air-max

Output: “air”

Trim

{{BLOCKNAME.products.0.name|trim}}

Input: “ air max "

Output: “air max”

Slugify

{{BLOCKNAME.products.0.name|slugify}}

Input: “Air Max”

Output: “air-max”

Unhyphenate

{{BLOCKNAME.products.0.name|unhyphenate}}

Input: “Air-Max”

Output: “Air Max”

pretty_time

{{nqe.created}}

{{nqe.created|pretty_time("%Y%m%d")}}

{{nqe.created|pretty_time("%m/%d/%Y %H:%M")}}

Formats time in the specified inputs.

add_time

Hurry, this offer ends {{nqe.created|add_time(3,'days')|pretty_time('%m/%d')}}

Add additional time to a given time. For example, this offer ends 2/18.

to_datetime

{{product.datetime_str|to_datetime()}}

{{product.datetime_str|to_datetime('%Y%m%d')}}

{{product.datetime_str|to_datetime('%Y%m%d')|pretty_time('%Y')}}

Turns a string into a datetime object. This can be combined with pretty_time.

hasattr

{% if product|hasattr('description') %}

{{product.description}}

{% endif %}

Returns a boolean value based on if an object has a given attribute.

product_any

{% if products|product_any('ineligible_for_coupon', [True]) %}

<!-- show specific legal copy -->

{% endif %}

Returns a boolean value based on if any product in a set has a given attribute set at a specific value.

Did this answer your question?