---
updatedAt: 2025-10-30T22:19:26.000Z
agentTools:
  projectIndex: https://docs.rejoiner.com/llms.txt
---

# Template Tags

## Basic Usage

Rejoiner's templating language uses template tags in order to inject dynamic data into your templates. Rejoiner uses <a href="https://docs.djangoproject.com/en/2.1/ref/templates/language/" target="_blank">Django</a> 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 of which can be used in combination in order to personalize and customize your campaigns.

<br />

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

<label class="code-label">Template Tag Structure</label>

```
{{ 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 them 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                              |
| `{{customer.metadata.custom_field}}` | Customer Metadata can be accessed on the `customer.metadata` key       |

> 📘 See the [Customer Profile](https://docs.rejoiner.com/reference/create-customer-profile) specification for a list of all available customer parameters.

***

### 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.#}}`<br /><br /><strong>Example:</strong><br />`{{cart_item.categories.0}}` | List a specific [index number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)\{: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:

<label class="code-label">Example:</label>

```
{% 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 <em>this specific cart</em> and therefore has a quantity and total price as well.

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        Viewed Item Tag
      </th>

      <th>
        Cart Item Tag
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `{{viewed_item.product.product_id}}`
      </td>

      <td>
        `{{cart_item.product.product_id}}`
      </td>

      <td>
        The product SKU or unique identifier
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.name}}`
      </td>

      <td>
        `{{cart_item.product.name}}`
      </td>

      <td>
        The name of the product
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.description}}`
      </td>

      <td>
        `{{cart_item.product.description}}`
      </td>

      <td>
        A short description of the product
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.price}}`
      </td>

      <td>
        `{{cart_item.product.price}}`
      </td>

      <td>
        The price of the product
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.image_url}}`
      </td>

      <td>
        `{{cart_item.product.image_url}}`
      </td>

      <td>
        The URL of the product image or thumbnail
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.product_url}}`
      </td>

      <td>
        `{{cart_item.product.product_url}}`
      </td>

      <td>
        The URL of the product page
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.categories}}`
      </td>

      <td>
        `{{cart_item.product.categories}}`
      </td>

      <td>
        The array of categories for a product
      </td>
    </tr>

    <tr>
      <td>
        `{{viewed_item.product.metadata.custom_field}}`
      </td>

      <td>
        `{{cart_item.product.metadata.custom_field}}`
      </td>

      <td>
        Custom data parameter for the product
      </td>
    </tr>
  </tbody>
</Table>

***

### Session Data

The following tags come from data attached to the customer's session. These are set via the [setSessionMetadata](https://docs.rejoiner.com/reference/setsessionmetadata) and the [setSessionDate](https://docs.rejoiner.com/reference/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](https://docs.rejoiner.com/docs/recommendations).

***

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

> 🚧 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")

<label class="code-label">Example:</label>

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

<div class="note red">
<p><strong>Important Note:</strong> The keyword values should not include any extra HTML. Doing so will cause your emails to not send.</p>
</div>

<label class="code-label">Let's assume we have the following `header_tag` snippet:</label>

```
<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:

<label class="code-label">Snippet Usage Example:</label>

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

### Sum List of Values

Occasionally, 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}`

<label class="code-label">Sum Unit Price</label>

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

Total: {% display_currency total_price_value %}
```

<label class="code-label"> Sum Total Price</label>

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

Total: {% display_currency total_cart_value %}
```

<label class="code-label">Sum Shipping Price (from metadata)</label>

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

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

<label class="code-label">Sum Shipping Price (including base price)</label>

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

Shipping: {% display_currency total_shipping_cost %}
```

<label class="code-label">Sum Gift Wrap Price (Sets 0 for missing values)</label>

```
{% 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 %}
```

<label class="code-label">Sum Gift Wrap Price (Returns 0 if any missing values)</label>

```
{% 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 "?")
```

<label class="code-label">Example:</label>

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

<label class="code-label">Examples:</label>

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

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>

      </th>

      <th>

      </th>

      <th>

      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        Filter
      </td>

      <td>
        Definition
      </td>

      <td>
        Usage
      </td>
    </tr>

    <tr>
      <td>
        `exclude_product_ids`
      </td>

      <td>
        Excludes listed categories from being injected
      </td>

      <td>
        `|exclude_product_ids:"prod_id_1,prod_id2" `
      </td>
    </tr>

    <tr>
      <td>
        `exclude_categories`
      </td>

      <td>
        Excludes listed categories from being injected
      </td>

      <td>
        `|exclude_categories:"prod_id_1,prod_id2"`
      </td>
    </tr>
  </tbody>
</Table>

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

<label class="code-label">Assume a cart item's price is $15 (1500 cents):</label>

```
# 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](#viewed-items-global-product-data) and has all of the product fields associated with the `.product` attribute of either `viewed_item` or `cart_item`.

<label class="code-label">Example Usage:</label>

```
{% 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.

<label class="code-label">Example Usage for Price Drop Product Injection</label>

```
{% 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.

<label class="code-label">Loop for Cart Items:</label>

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

<label class="code-label">Loop for Viewed Items:</label>

```
{% 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.

<label class="code-label">Example for Cart Items:</label>

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

<label class="code-label">Example for Viewed Items:</label>

```
{% 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.

<label class="code-label">Example for Cart Items:</label>

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

<label class="code-label">Example for Viewed Items:</label>

```
{% 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`.

<label class="code-label">Example for Cart Items:</label>

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

<label class="code-label">Example for Viewed Items:</label>

```
{% 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.

<label class="code-label">Example for Cart Items:</label>

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

<label class="code-label">Example for Viewed Items:</label>

```
{% 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 %}
```