DOCUMENTATION

Template Tags

Rejoiner Template Tags

Basics

Rejoiner's templating language uses template tags in order to inject dynamic data into your templates. Rejoiner uses Django as the base for our templating system.

This means that the data being displayed in every single email for each of your customers will always be correct. You can always decide what to inject and what not to use in order to best fit your campaign's strategy.

Rejoiner's templating language consists of cart, cart_item, viewed_item, contact, recommendations, customer and session tags, field tags, loop tags, filter tags—all which can be used in combination in order to personalize and customize you campaigns.


Template Tags Structure

To print a merge tag, you'd use double curly brackets along the dataset_name.attribute structure you'd like to inject inside the brackets, like in the example below:

{{ customer.email }}

Datasets

Dataset refers to the collected set of information that we gather from your site.

Description Attribute
Pertains to the data set of collected information of a customer's cart value cart
Pertains to the data set of collected information of carted items added by a customer cart_item
Pertains to the data set of collected information of items browsed by a customer viewed_item
Pertains to the data set of collected information about a list contact contact
Pertains to the data set of collection information about an existing customer customer
Pertains to the data set of collected information about a customer's session session

Attribute Names

Attribute names refer to the specific parameter you want to inject into your templates. Each dataset collects different parameters, which are listed in our API docs.

Below you will find a listing of all of our available merge tags classified by Dataset so it is easier for you to implement into your campaigns.

Available Data Tags

Customer Data

Use these merge tags when injecting dynamic data about a customer.

Customer Data Tag Description
{{customer.id}} The customer's id, which is the hashed email address of a customer
{{customer.email}} The email address of a customer
{{customer.first_name}} The first name of a customer—if available

Cart Data

Use these merge tags when injecting dynamic data about a customer's cart data, such as total cart value, total cart items, etc.

Cart Data Tag Description
{{cart.return_url}} A unique URL that regenerates the cart when clicked on
{{cart.item_count}} The total number of items in the cart
{{cart.value}} The total value of the cart in cents
{{cart.order_number}} A unique order number or confirmation number
{{cart.promo}} A unique promo code or coupon
{{cart.metadata.custom_field}} Custom data parameter

Cart Items

The cart items dataset is an array of CartItem objects. The following describes the fields available for a single CartItem object.

Cart Item Tag Description
{{cart_item.product.product_id}} A product SKU or unique identifier
{{cart_item.name}} The name of the cart item
{{cart_item.description}} A short description of the cart item
{{cart_item.price}} The price of a specific item in cents
{{cart_item.qty}} The quantity of an item in the cart
{{cart_item.total_price}} This is the price x quantity of an item
{{cart_item.expiration_date}} This is the expiration date of an item
{{cart_item.image_url}} The URL of the cart item image or thumbnail
{{cart_item.categories}} Lists all of the cart item categories (better known as a category array) of a cart item.
{{cart_item.categories.#}}

Example:
{{cart_item.categories.0}}
List a specific index number{:target="blank"} from the category array of a cart item
{{cart_item.product_url}} The URL of the product page for a specific item
{{cart_item.metadata.custom_param_name}} Custom data parameter

If you wanted to display all cart item categories of a specific item you can use the following example:

{% for category in cart_item.categories %}{{category}}{% endfor %}

Viewed Items & Global Product Data

Additionally, the global product data collected from trackProductView is also associated with the cart item. This global product data may not necessarily be the same as the associated field on the cart item. The cart item object is a representation of this product in this specific cart and therefore has a quantity and total price as well.

Viewed Item Tag Cart Item Tag Description
{{viewed_item.product.product_id}} {{cart_item.product.product_id}} The product SKU or unique identifier
{{viewed_item.product.name}} {{cart_item.product.name}} The name of the product
{{viewed_item.product.description}} {{cart_item.product.description}} A short description of the product
{{viewed_item.product.price}} {{cart_item.product.price}} The price of the product
{{viewed_item.product.image_url}} {{cart_item.product.image_url}} The URL of the product image or thumbnail
{{viewed_item.product.product_url}} {{cart_item.product.product_url}} The URL of the product page
{{viewed_item.product.categories}} {{cart_item.product.categories}} The array of categories for a product
{{viewed_item.product.metadata.custom_field}} {{cart_item.product.metadata.custom_field}} Custom data parameter for the product

Session Data

The following tags come from data attached to the customer's session. These are set via the setSessionMetadata and the setSessionDate.

Session Tag Description
{{session.metadata.custom_field}} Custom data parameter
{{session.metadata.price_change_product_id}} Product ID for a product whose price dropped
{{session.metadata.price_change_previous_price}} The previous price of a price dropped product
{{session.metadata.price_change_new_price}} The new price of a price dropped product
{{session.payment_date}} Date value for payment_date
{{session.fulfillment_date}} Date value for fulfillment_date
{{session.delivery_date}} Date value for delivery_date

List Contact Tags

Use the following tags to inject data that pertains to a customer in a List. These tags are most commonly used in broadcasts, but can be used in any other Journey type.

Viewed Item Tag Description
{{customer.email}} The email of a list contact
{{customer.first_name}} First name field
{{contact.custom_fields.custom_field_name}} Custom list field

Site

Use these merge tags when injecting dynamic data based on the current settings for the site.

Site Tag Description
{{site.url}} The fully qualified url for the site
{{site.timezone}} The selected timezone for the site
{{site.currency}} The selected currency for the site

Product Recommendations

For detailed documentation on how to inject product recommendations, see the Product Recommendations Docs.

Miscellaneous Tags

Tag Description
{{unsubscribe_url}} Injects link to customer's unsubscribe page
{{opt_in_url}} Injects an explicit opt-in link
{{subscription_preferences_url}} Injects link to customer's preferences page
{% now "Y" %} Injects the current year. Usually used in the footer of an email next to the © info.

Action Tags

Action tags take one of two forms: tags and filters. Both perform an action on some data but work slightly differently.

An action tag looks like {% tag_name option1 option2 ... %} while a filter looks like {{ data|filter:option }}. The key difference is that an action tag does not necessarily take in data and does not necessarily insert anything into the template while a filter performs an action on data and inserts it into the template (or passes it on to another filter).

Important Note: Any options surrounded by quotes (e.g "option value" or 'option value') will be inserted as-is. As such any merge tags in a quoted string will not be expanded to it's value.

Displaying Currency

The display_currency tag can be used to display a currency with the desired symbols and format. It takes 3 options:

  1. value_in_cents — The value to be displayed as an integer in cents.
  2. currency — The currency to be displayed in (default: "USD")
  3. locale — The locale to format the currency (default: "en_US")

# EXAMPLES (Assuming cart.value = 1000)
{% display_currency cart.value %}
# $10.00
{% display_currency cart.value 'EUR' %}
# €10.00
{% display_currency cart.value 'EUR' 'fr_FR' %}
# 10,00 €

Including Snippets

The include_snippet tag can be used to render and insert a saved snippet of HTML from your Site's snippet collection. It takes a single required option:

slug - The unique name of the snippet to include

Any other options passed as keywords (option_name=option_value) will be passed into the snippet template as template tags for use within the snippet.

Important Note: The keyword values should not include any extra HTML. Doing so will cause your emails to not send.

<img src="/img/emails/logo.png" style="display:block;border:0;" width="100" />
<span>{{ contact_number }}</span>

We would then include the snippet like so in the email creative:

{% include_snippet header_tag contact_number="+1 800-234-5678" %}

Sum List of Values

Occassionally, it makes more sense to display the sum of a list of values, such as cart item or product view prices. This may happen if there is a different value that you'd like to display, such as the sum of a value inside metadata.

The tag takes two required arguments:

  1. items - The items which contain an attribute to be summed
  2. attr - The attribute to retrieve from each item. Can be nested or part of metadata with a . (e.g. metadata.key or product.price)

The tag also takes a few optional arguments:

  1. item_default - The value to use if a value cannot be retrieved from an item
  2. default - The value to use if the values cannot be summed (e.g. different types or missing data)
  3. initial - The value to start with prior to adding the values retrieved from the items

The following examples assume you have the following cart items:

Cart Item #1 - price: 1000 - qty: 2 - total_price: 2000 - metadata: {"shipping": 300, "gift_wrap": 100}

Cart Item #2 - price: 500 - qty: 1 - total_price: 500 - metadata: {"shipping": 50}

{% get_sum cart_items 'price' as total_items_price_value %} 
# Returns --> 1500

Total: {% display_currency total_price_value %}

{% get_sum cart_items 'total_price' as total_cart_value  %} 
# Returns --> 2500

Total: {% display_currency total_cart_value %}

{% get_sum cart_items 'metadata.shipping' as total_cart_value_plus_shipping %}
# Returns  --> 350

Total (Shipping Included): {% display_currency total_cart_value_plus_shipping %}

{% get_sum cart_items 'metadata.shipping' initial=500 as total_shipping_cost%}  
# Returns  --> 850

Shipping: {% display_currency total_shipping_cost %}

{% get_sum cart_items 'metadata.gift_wrap' item_default=0 as total_gift_wrap_cost %}  
# Returns  --> 100

Gift Wrap : {% display_currency total_gift_wrap_cost %}

{% get_sum cart_items 'metadata.gift_wrap' default=0 as total_items_gift_wrap_cost %}
# Returns  --> 0

Filters

Appending Parameters to a Query String

The append_query filter can be used to add additional parameters to a query string for a url. This will overwrite any existing parameters with the same key and correctly format the query string if it does not already exist. It has one required option:

query - The query string parameters to append (without the leading "?")

# Single Parameter
{{cart.return_url|append_query:"promo=test123"}}
# Multiple Parameters
{{cart_item.product_url|append_query:"promo=test123&other=value"}}

Number Display Filters

The following filters will format a number into a nicer display value

  • intcomma - Insert a comma every 3 decimal places (e.g. 10000 becomes 10,000)
  • ordinal - Displays the ordinal representation of a value (e.g. 1 becomes 1st, 2 becomes 2nd, ...)

# If you have 10,000 of something...
{{cart_item.qty}}          --> 10000
{{cart_item.qty|intcomma}} --> 10,000

# Ordinal Numbers
{% for category in cart_item.categories %}
{{ forloop.counter|ordinal }} Category --> 1st Category
{% endfor %}

Exclude products

A template may contain references to products such as cart_items or viewed_items. In the case where we want to exclude specific products to be injected into the cart_items or viewed_items we can list the products to exclude by using the following options:

Filter Definition Usage
exclude_product_ids Excludes listed categories from being injected |exclude_product_ids:"prod_id_1,prod_id2"
exclude_categories Excludes listed categories from being injected |exclude_categories:"prod_id_1,prod_id2"

Math Filters

The following filters are available to perform basic math functions between two numbers. All of these filters take a required argument of a number.

  • add - Adds the argument to the value
  • sub - Subtracts the argument from the value
  • mul - Multiplies the value by the argument
  • div - Divides the value by the argument
  • intdiv - Divides the value by the argument and ignores any remainder (also known as "floor division")
  • abs - Takes the absolute value of the value
  • mod - Takes the modulo of the value by the argument

# Add $10 to cart item price (1500 + 1000)
{{cart_item.price|add:1000}} --> 2500
{% display_currency cart_item.price|add:1000 %} --> $25.00

# Subtract $10 from cart item price (1500 - 1000)
{{cart_item.price|sub:1000}} --> 500

# Multiply cart item price by 90% (10% off) (1500 x 0.9)
{{cart_item.price|mul:0.9}} --> 1350

# Divide cart item by 9 (1500 / 9)
{{cart_item.price|div:9}} --> 166.67

# Divice cart item by 9, ignoring remainder (FLOOR(1500 / 9))
{{cart_item.price|intdiv:9}} --> 166

# Take absolute value of negative number
{{cart_item.price|mul:"-1"|abs }} --> 1500

# Take cart item price modulo 9 (1500 % 9)
{{cart_item.price|mod:9 }} --> 6

Retrieving a Specific Product

The get_product tag can be used to retrieve information about a specific product ID, regardless of if the product was carted or viewed.

If the product is found, the resulting value is of the same form as the Viewed Items & Global Product Data and has all of the product fields associated with the .product attribute of either viewed_item or cart_item.

{% get_product 'my-product-id' as my_product %}

<img src="{{ my_product.image_url }}" />
<span class="product-title">{{ my_product.name }}</span>
<p>{{ my_product.description }}</p>
<span>{% display_currency my_product.price %}</span>
<a href="{{ my_product.product_url }}">Buy Now!</a>

Price Drop Example

A Journey can be triggered when a product’s price has changed. For example, if an identifiable customer recently viewed or carted (but did not purchase) a Hat that was $20, that customer can be emailed automatically if the price of that Hat drops to $10.

If an identifiable customer recently viewed or carted multiple items whose prices have changed, the first product to change price will take precedence (i.e. only one product price drop notification will be sent).

Use the example below for injecting a product whose price dropped for a Price Drop email notification.

{% get_product session.metadata.price_change_product_id as price_dropped_item %}
{% if price_dropped_item %}
<img src="{{ price_dropped_item.image_url }}" />
<span class="product-title">{{ price_dropped_item.name }}</span>
<p>{{ price_dropped_item.description }}</p>
<p>Price Before: {% display_currency session.metadata.price_change_previous_price %}</p>
<p>Price Now: {% display_currency session.metadata.price_change_new_price %}</p>
<a href="{{ price_dropped_item.product_url }}">Buy Now!</a>
{% endif %}

Looping

Tags that look like this {% tag %} serve as logic controls and by default are more complex than the merge tags mentioned above. The use of the logic loop tags requires you to use them along with {{template tags}}.

Below you have three basic options for injecting cart items into an HTML email:

  • Show all items
  • Show one item only
  • Show the last item added / viewed
  • Show a specific number of items

Show ALL Items

This method will inject all cart_items or all viewed_items from a customer's session. You'll want to surround the section that holds your item's template tags with the loop below so that only that specific section repeats for every item that will be injected.

{% for cart_item in cart_items %}
  <!-- HTML Code --> 
{% endfor %}

{% for viewed_item in viewed_items %}
  <!-- HTML Code --> 
{% endfor %}

Show One Item Only

The method below works best when you only want to inject only 1 item from a customer's session.

{% for cart_item in cart_items %} {% if forloop.counter = 1 %} 
  <!-- HTML Code --> 
{% endif %} {% endfor %}

{% for viewed_item in viewed_items %} {% if forloop.counter = 1 %} 
  <!-- HTML Code --> 
{% endif %} {% endfor %}

Show the Last Item Added/Viewed

Items are sorted by carted/viewed date in ascending order. This means that—for example—if we want to inject the last cart item, we have to call the last item in the assortment. This method works best when you want to secure the injection of the most recent item.

{% for cart_item in cart_items %} {% if forloop.last %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

{% for viewed_item in viewed_items %} {% if forloop.last %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

If you wanted to show the first item added/viewed in a customer's session, you'd simply have to change .last for .first.

{% for cart_item in cart_items %} {% if forloop.first %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

{% for viewed_item in viewed_items %} {% if forloop.first %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

Show Cart Items in Reverse Order

Use this approach if you'd like to inject cart items in the reverse order that they were added to the cart. In other words, you'd like to inject all items, starting with the last item that was added.

{% for cart_item in cart_items reversed %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

{% for viewed_item in viewed_items reversed %} 
  <!-- HTML Code -->
{% endif %} {% endfor %}

Show a Specific Number of Items

To inject a specific number we will use the slice method, which returns a slice of the item list. This method can only be used within logic loop tags.

The method works this way |slice:":NumberOfItems"

So for example, if you want to inject 3 cart_items, you'll call the slice method by using |slice:":3" as demonstrated below:

{% for cart_item in cart_items|slice:":3" %}
  <!-- HTML Code -->
{% endfor %}

So for example, if you want to inject 5 viewed_items, you'll call the slice method by using |slice:":5" as demonstrated below:

{% for viewed_item in viewed_items|slice:":5" %}
  <!-- HTML Code -->
{% endfor %}

Back to Top