Rejoiner's Template Language

In this tutorial, you'll learn how to use merge tags to dynamically inject cart data into your HTML templates.

In This Article

 

Basics

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

Rejoiner's templating language consists of system merge tags, field tags, loop tags, filter tags – all which can be used in combination in order to personalize and customize you campaigns. Through this tutorial we will focus solely on how to inject cart data, cart items and viewed items in your templates. To see how to implement recommendations  click here.

 

Merge Tag Structure

To print a merge tag, you'd use double curly brackets {{ }} along the dataset_name.attribute_name structure you'd like to inject inside the brackets, like so:

{{dataset_name.attribute_name}}

Examples:
{{cart_data.return_url}}
{{cart_item.fields.name}}
{{viewed_item.fields.image_url}}
Datasets

Dataset refers to the collected set of (either) cart information, cart item information, or viewed item information that we gather from your site. 

Attribute Description
cart_data Pertains to the data set of collected information of a customer's cart value
cart_item Pertains to the data set of collected information of carted items added by a customer
viewed_item Pertains to the data set of collected information of items browsed by a customer
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  JavaScript API Endpoints guide. 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 Merge Tags

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.

Attribute Description
{{cart_data.email}} The email address of a customer
{{cart_data.return_url}} A unique URL that regenerates the cart when clicked on
{{cart_data.total_items}} The total number of items in the cart
{{cart_data.value|cents_to_dollars}} The total value of the cart converted to dollars
{{cart_items|sum_qty_price|cents_to_dollars}} The total sum value of ALL of the customer's cart items
{{cart_data.customer_order_number}} A unique order number or confirmation number
{{cart_data.promo}} A unique promo code or coupon
Note: cart_data merge tags can only be used in cart abandonment campaigns

Example Usage **

<table>	
    <tr>
       <td>
           Your Order Number: {{cart_data.customer_order_number}} includes {{cart_data.total_items}}
       </td>
    </tr>
    <tr>
       <td>
            <a href="{{cart_data.return_url}}" target="_blank">Complete Your Order</a>
        </td>
    </tr>
</table>
** This example is just for demonstration purposes, not a template.

Results

CART ITEMS

Cart item merge tags must be wrapped in loop tags. See below for more information.
Attribute Description
{{cart_item.fields.product_id}} A product SKU or unique identifier
{{cart_item.fields.name}} The name of the product
{{cart_item.fields.description}} A short description of the product
{{cart_item.fields.price|cents_to_dollars}} The price of a specific item converted to dollars
{{cart_item.fields.item_qty}} The quantity of an item in the cart
{{cart_item.fields.qty_price}} This is the price x quantity of an item
{{cart_item.fields.image_url}} The URL of the product image or thumbnail
{{cart_item.fields.categories}} Lists all of the product categories (better known as a category array) of a cart item.
{{cart_item.fields.category}} The product category of a specific item
{{cart_item.fields.categories.#}}

   Examples:
{{cart_item.fields.categories.1}}
{{cart_item.fields.categories.0}}
{{cart_item.fields.categories.2}}
Lists a specific  index number from the category array of a cart item.
{% for category in cart_item.fields.categories %} {{category}} {% endfor %} All product categories of a specific item
{{cart_item.fields.product_url}} The URL of the product page for a specific item

Example Usage **

<!-- START CART SECTION -->
{% for cart_item in cart_items %}{% if forloop.last %}
<table>
    <tbody>
        <tr>
              <td>
                 Here's a quick reminder of your cart:
              </td>
        </tr>
        <tr>
              <td>
                  <table>
                      <tbody>
                           <tr>
                              <td>
                                  <a href="{{cart_item.fields.product_url}}" target="_blank"><img src="{{cart_item.fields.image_url}}" alt="{{cart_item.fields.name}}"/></a>
                              </td>
                           </tr>
                      </tbody>
                  </table>
              </td>
        </tr>
        <tr>
              <td>
                  <a href="{{cart_item.fields.product_url}}" target="_blank">{{cart_item.fields.name}}</a>
              </td>
        </tr>
        <tr>
              <td>
                  Quantity: {{cart_item.fields.item_qty}}
                  Price: ${{cart_item.fields.price|cents_to_dollars}}
                  Item Code: {{cart_item.fields.product_id}}
              </td>
        </tr>
    </tbody>
</table>
<table>
    <tbody>
        <tr>
              <td>
                  <a href="{{cart_data.return_url}}" target="_blank">CONTINUE SHOPPING</a> 
              </td>
        </tr>
    </tbody>
</table>
{% endif %}{% endfor %}
<!-- END CART SECTION -->
** This example is just for demonstration purposes, not a template.

Results

VIEWED ITEMS

Use these merge tags when injecting dynamic data about a customer's browsing history.

Attribute Description
{{viewed_item.fields.name}} The name of the item a customer browsed/viewed.
{{viewed_item.fields.image_url}} The image path of the item a customer browsed/viewed.
{{viewed_item.fields.product_url}} The URL address of the item's product page a customer browsed/viewed.

Example Usage **

<table>
    <tbody>	
       <tr>
            <td>
               You were checking us out! That's okay, we like it. Here's what you were looking at in our store.
            </td>
        </tr>
        <tr>
            <td>
              <a href="{{view_item.fields.product_url}}" target="_blank"><img src="{{viewed_item.fields.image_url}}" alt="{{view_item.fields.name}}" /></a>
              {{viewed_item.fields.name}}
              <a href="{{view_item.fields.product_url}}">Add to Cart</a>
            </td>
        </tr>
    </tbody>
</table>
** This example is just for demonstration purposes, not a template.

Results

LEAD TAGS

To be used in New Subscriber and Broadcast campaigns only.

Attribute Description
{{lead.email}} Inject the email of a lead
{{lead.first_name}} First Name Field
{{lead.custom_1}} Custom List Field #1
{{lead.custom_2}} Custom List Field #2
{{lead.custom_3}} Custom List Field #3
{{lead.custom_4}} Custom List Field #4
{{lead.custom_5}} Custom List Field #5
{{lead.custom_6}} Custom List Field #6

Example usage

Hi {{lead.first_name}}!

For more information on how to use Custom List Fields,  go here.

MISCELLANEOUS TAGS

Attribute Description
{{unsubscribe}} Inject an unsubscribe link
{{cart_data.return_url|append_query:'?promo=rjr123'}} Append a query string onto return_url
{{cart_data.return_url|append_query:'?utm_source=rejoiner'}} Append UTM parameters from Google Analytics via query string onto return_url
{{cart_items|sum_qty_price|dicount:10|cents_to_dollars}} Calculates the sum value of ALL the items in a customer's cart and applies a percentage discount. 

Example usage

Unsubscribe:
<a href="{{unsubscribe}}" target="_blank">Unsubscribe</a> from these messages.

Append Promo Code:
<a href="{{cart_data.return_url|append_query:'?promo=backtoda20'}}" target="_blank">Return to Cart</a>

Append UTM Parameters:
<a href="{{cart_data.return_url|append_query:'?utm_source=rejoiner&utm_medium=email&utm_campaign=ca1'}}" target="_blank">Return to Cart</a>

Cart Items Sum with Discount Total:
<p>Your New Cart Total (with 10% off):{{cart_items|sum_qty_price|discount:10|cents_to_dollars}}</p>

 

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 {{merge tags}}.

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

  1. Show all cart items
  2. Show only one item
  3. Show the last item only
  4. Show a specific number of items

Showing ALL items will loop through each item in the cart and inject each one into your email. This is ideal for re-creating a table of ALL abandoned cart items. Showing the first cart item will only inject one item from the customer's cart into the creative. You can use merge tags in your email body or subject lines.

Option 1: Inject all cart_items

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

We recommend keeping your cart_data tags separate in your HTML structure.
Loop for Cart Items:
{% for cart_item in cart_items %} <!-- HTML Code --> {% endfor %}
Loop for Viewed Items:
{% for viewed_item in viewed_items %} <!-- HTML Code --> {% endfor %}

Example Using Cart Items

<table>
    <tr>
        <td>
            Here is a reminder of your cart:
        </td>
    </tr>
</table>
<!-- call and inject all items -->
{% for cart_item in cart_items %} 
<table>
    <tr>
        <td>
            Name: {{cart_item.fields.name}}
            Price: ${{cart_item.fields.price|cents_to_dollars}}
        </td>
    </tr>
</table>
{% endfor %}
<!-- end call -->
<table>
    <tr>
        <td>
            Complete your order: {{cart_data.return_url}}
        </td>
    </tr>
</table>

Option 2: Inject only one viewed_item

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

Loop + 1 Item Conditional for Cart Items:
{% for cart_item in cart_items %} {% if forloop.counter = 1 %} <!-- HTML Code --> {% endif %} {% endfor %}
Loop + 1 Item Conditional for Viewed Items:
{% for viewed_item in viewed_items %} {% if forloop.counter = 1 %} <!-- HTML Code --> {% endif %} {% endfor %}
We recommend keeping your cart_data tags separate in your HTML structure.

Example Using Viewed Items

<!-- call all items -->
{% for viewed_item in viewed_items %}
<!-- inject one item only -->
{% if forloop.counter = 1 %}
<table>
    <tr>
        <td>
        Name: {{viewed_item.fields.name}} 
        Image: ${{viewed_item.fields.image_url}} 
       </td>
    </tr>
</table>
{% endif %}
        <!-- end if statement -->
        {% endfor %}
        <!-- end call -->
<table>
    <tr>
        <td>
            Complete your order: {{cart_data.return_url}}
        </td>
    </tr>
</table>

Option 3: Inject the last cart_item only

Cart items are sorted by carted date in ascending order. This means that 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.

To inject the last cart_item added to an email, you'll should use the example loops below:

Loop + Last Item Conditional for Cart Items:
{% for cart_item in cart_items %} {% if forloop.last %} <!-- HTML Code --> {% endif %} {% endfor %}
Loop + Last Item Conditional for Viewed Items:
{% for cart_item in cart_items %} {% if forloop.last %} <!-- HTML Code --> {% endif %} {% endfor %}
We recommend keeping your cart_data tags separate in your HTML structure.

Example Using CART Items

<!-- call all items -->
{% for cart_item in cart_items %}
<!-- inject one item only -->
{% if forloop.counter = 1 %}
<table>
    <tr>
        <td>
        Image: ${{cart_item.fields.image_url}}
        Name: {{cart_item.fields.name}} 
        Item Qty: {{cart_item.fields.item_qty}}
        Price: ${{cart_item.fields.price|cents_to_dollars}}
        Product Subtotal: ${{cart_item.fields.qty_price|cents_to_dollars}}
        Product URL: ${{cart_item.fields.product_url}}
       </td>
    </tr>
</table>
{% endif %}
<!-- end if statement -->
{% endfor %}
<!-- end call -->
<table>
    <tr>
        <td>
            Complete your order: {{cart_data.return_url}}
        </td>
    </tr>
</table>
Note: If you wanted to show the first cart_item added in a customer's session, you'd simply have to change .last for .first

The above works only for CART items. If you wanted to inject the last VIEWED item you would have to call the first item in the assortment. This method works best when you want to secure the injection of the most recent item as viewed items are sorted by browsed date in descending order. 

To inject the last  viewed_item browsed to an email, you'll should use the example loops below:

{% for viewed_item in viewed_items %} {% if forloop.first %} <!-- HTML Code --> {% endif %}{% endfor %}
Note: If you wanted to show the first viewed_item added in a customer's session, you'd simply have to change .first for .last

Option 4: Inject a specific number of viewed 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 items, you'll call the slice method by using |slice:":3" as demonstrated below:

<!-- call all viewed items -->
{% for viewed_item in viewed_items|slice:":3" %}
<table>
    <tr>
        <td>
            <!-- inject viewed item data -->
            Name: {{viewed_item.fields.name}}
            Url: {{viewed_item.fields.product_url}}
        </td>
    </tr>
</table>
{% endfor %}
<!-- end for loop -->
<table>
    <tr>
        <td>
            Complete your order: {{cart_data.return_url}}
        </td>
    </tr>
</table>
Note: If you only want to inject one item, we recommend using the method from Option 2.

 

Personalization

The most common use case for personalization is to inject a customer's first name into an email. To use personalization, we have a standard name tag to help you: {{name}}

In order to use the above merge tag, you must send us a customer's name via the  name endpoint of our API. If you're not using setCustomerData to pass us the name, you can use the field name of the First Name input on your checkout flow. This will enable you to inject the name data captured from the name field on your checkout page. 

 

Name Email Settings

In order to leverage this backup option via a field's name, you must first identify the name of the field you wish to inject as a {{name}}. Next, you'll need to add this field name in your Email settings as shown in the video below.

 

Name Fallback & Conditional

In some cases, a customer may not add their name in the checkout process, thus we should display a default value as a fallback.

Example: Hello  {{name|default:'Friend'}},

NAME CONDITIONAL

Sometimes, you'd like to inject a customer's name within a personalized sentence like: "James, you forgot these items" while avoiding default text from appearing, like so: "Friend, you forgot these items"  

In that case we'd use a conditional, like the example below:

{% if name %}
{{name}}, you forgot these items.
{% else %}
You forgot these items.
{% endif %}

The above example snippet could also be done in just one line:

{% if name %}{{name}}, you forgot these items.{% else %}You forgot these items.{% endif %}

As an extra detail, some users may input their name in lowercase or even all in uppercase. In order to capitalize the first letter of their name only, you'd want to add a filter to the name tag like so:

{{name|capfirst}}

This would then turn something like "karen" or "KAREN" into:  Karen

Still need help? Contact Us Contact Us