Advanced Methods

All of the examples above are part of our basic usage of merge tags. We have other complex methods that show all the possibilities inside our application. Note that usage of these advanced methods may require knowledge with  Django Template Tags

Item Data Conditionals

The Rejoiner templating language gives you the ability to show or hide sections in your email based on conditional criteria. This criteria can be defined out of viewed item data and cart item data. Below we will show you 3 of our most popular examples.

1
Using Total Cart Value as a Conditional

Our most popular use of this example is showing a code snippet, or text when a user qualifies for Free Shipping based on a customer's total cart value. We will use this example as a guide, but feel free to experiment.

To start off let's set some rules. Let's say that if a customer's order equals or is greater than $150 in total value, they get free shipping. However, you want to offer these customers Expedited Shipping via a promotional code to encourage a purchase. 

We will start by creating our conditional via a loop tag. This conditional should say if cart_data.value|cents_to_dollars is >= (greater than) $150 - show this.

{% if cart_data.value|cents_to_dollars >= 150.00 %} {% endif %}
Note: We're not using the {{ }} brackets that are part of the {{cart_data.value|cents_to_dollars}} merge tag, instead we're just using the data and value it represents.

This means that we want to show the code ONLY to those that qualify using the snippet below:

 
<!-- Expedited Shipping Conditional Snippet -->
{% if cart_data.value|cents_to_dollars >= 150.00 %}
Use code: FASTSHIP today and get free Expedited Shipping on us!
{% endif %}
<!-- end Expedited Shipping Snippet -->

Now, let's say that you want to show the promo code to all that qualify, and a reminder of your free shipping terms to those that don't. Then we'd want to use the snippet below with an else statement for those that do not qualify

<!-- Expedited Shipping Conditional Snippet -->
{% if cart_data.value|cents_to_dollars >= 150.00 %}
Use code: FREESHIP today and get free shipping on us!
{% else %}
Remember, all orders above $150 qualify for free shipping!
{% endif %}
<!-- end Expedited Shipping Snippet -->

Example Usage **

<!-- Expedited Shipping Conditional Snippet -->
{% if cart_data.value|cents_to_dollars >= 150.00 %}
<table>
    <tr>
        <td>
           Use code: FREESHIP today and get free shipping on us!
        </td>
    </tr>
</table>
{% else %}
<table>
    <tr>
        <td>
            Remember, all orders above $150 qualify for free shipping!
        </td>
    </tr>
</table>
{% endif %}
<!-- end Expedited Shipping Snippet -->
2
Using Product ID or Product Name as a Conditional

Our most popular use of this example is showing a code snippet, or text when a user has a specific item in their shopping cart. Let's say that you have a new product called: Expandable Photography Bag, which is a new item in your catalogue and so you want to promote the item without segmenting your customers. 

To start off let's set some rules. Let's say that if a customer's abandoned order contains the product name of "Expandable Photography Bag", they will see a "new product" image alert

We will start by creating our conditional via a loop tag. This conditional should say if cart_item.fields.name is == "Expandable Photography Bag"  - show new product alert.

{% if cart_item.fields.name == "Expandable Photography Bag" %} {% endif %}
Note: We're not using the {{ }} brackets that are part of the {{cart_item.fields.name}} merge tag, instead we're just using the data it represents. Also, note that when we wish to make a comparison, such as in an if statement where the condition is either true or false, we have to use the double equals sign (==). 

This means that we want to show the code ONLY to those that qualify using the snippet below:

{% for cart_item in cart_items %}
Name: {{cart.item.fields.name}}
Product Image: {{cart.item.fields.image_url}}
<!-- New Product Conditional Image -->
{% if cart_item.fields.name == "Expandable Photography Bag" %}
<img src="http://www.mystore.com/images/new-product-alert.png" >
{% endif %}
Product URL: {{cart.item.fields.product_url}}
<!-- end New Product Conditional Image -->
{% endfor %}

Example Usage **

<!-- Cart Section -->
{% for cart_item in cart_items %}
<table>
    <tr>
        <td>
            <img src="{{cart_item.fields.image_url}}" />
        </td>
    </tr>
    <!-- new product conditional -->
    {% if cart_item.fields.name == "Expandable Photography Bag" %}
    <tr>
        <td>
            <img src="http://www.mystore.com/images/new-product-alert.png" />
        </td>
    </tr>
    {% endif %}
    <!-- end new product conditional -->
    <tr>
        <td>
            <p>{{cart_item.fields.name}}</p>
            <a href="{{cart_item.fields.product_url}}" target="_blank">View Product</a>
        </td>
    </tr>
</table>
{% endfor %}
<!-- end -->
Just as we used {{cart_item.fields.name}} we can create any other conditional using item data. Thus, if you have two new products with the same name you could always target the product to promote using the item's SKU via {{cart_item.fields.product_id}}.
3
Plural vs Singular Text - Depending on Total Item Count
Let's say that the text in your email template has some copy that could benefit from accuracy in depicting how many items are were left behind. This is another one of our most popular cases. The text below, reflects this issue, as you'd like to implement something that better personalizes the email for your customers.

Hey Dan,

My name is Sandra and I noticed that you left  some products in your Cult Beauty shopping bag. 

Perhaps you had questions about a product, a specific beauty concern, shipping options or maybe you had some trouble checking out?  

Drop me a line. I’m a trained beauty specialist so just reply to this email if you have a query and I will do my best to help. By the way, here’s a quick reminder of what you left behind. If you’re ready to complete your order click here.

So you'd want to solve this issue by creating a conditional with the following rules:


If Customer's Order Has One Item, Say: If Customer's Order Has More Than One Item, Say:
...you left something in your Cult Beauty shopping bag... ...you left some products in your Cult Beauty shopping bag....

For that we will use the conditional below, which uses the data gathered about the customer's order and use the injection of the {{cart_data.total_items}} merge tag.

{% if cart_data.total_items > 1 %} some products {% else %} something {% endif %}

Example Usage **

<table>
    <tr>
        <td>
            <p>Hey {{fields.names|super_key:'billing[firstname]'|default:'there'}},<p>
            <!-- plural - singular text conditional -->
            {% if cart_data.total_items > 1 %}
            <p>My name is Sandra and I noticed that you left some products in your Cult Beauty shopping bag.</p>
            {% else %}
            <p>My name is Sandra and I noticed that you left something in your Cult Beauty shopping bag.</p>
            {% endif %}
            <!-- end conditional -->
            <p>Perhaps you had questions about a product, a specific beauty concern, shipping options or maybe you had some trouble checking out?</p> 
            <p>Drop me a line. I’m a trained beauty specialist so just reply to this email if you have a query and I will do my best to help. By the way, here’s a quick reminder of what you left behind. If you’re ready to complete your order click here.
        </td>
    </tr>
</table>

Defining Variables

In Rejoiner we will want to create variables to re-use in an email's code using the {% with %} built in, which caches a complex variable under a simpler name. This is useful when accessing an “expensive” method (e.g., one that hits the database) multiple times.

In order to help you understand the power of this, we'll create a variable that will simplify the method of injecting the last item a customer abandoned in their cart.

1
Last Item with Defined Variable

First we will create a name for our variable, let's say we call it "last_item"

Next we will want to define the variable and set the definition inside our template using {% with %}. We know that items are injected in a descending order so if we want to inject only the last item that a customer abandoned (for example), we will have to call in the 1st item in the list. For this we can use  Django's first builtin method while calling the list of "cart_items". We do this as follows:

{% with last_item=cart_items|last %} {% endwith %}

Now that our variable is set, we can call it inside our merge tags. Thus instead of using the dataset of cart_item, we'll be using last_item as the dataset to call. We also do not need to use a forloop because we've already defined the cart_items list inside our variable's definitions. 

Meaning that now {{cart_item.fields.name}} can be called by using {{last_item.fields.name}}.

This may sound a bit technical, but it saves time, uses less code and it's easier to read. 

Below we have a full example of how to implement this in a campaign along a live example.

Example Usage **

<!-- cart section -->
{% with last_item=cart_items|last %}
<table>
    <tr>
        <td>
            <p>Here's a quick reminder of your cart:</p>
        </td>
    </tr>
    <tr>
        <td>
            <img src="{{last_item.fields.image_url}}" alt="{{last_item.fields.name}}" />
        </td>
    </tr>
    <tr>
        <td>
            <p>{{last_item.fields.name}}</p>
        </td>
    </tr>
    <tr>
        <td>
            <p>Quantity: {{last_item.fields.item_qty}}</p>
            <p>Price: ${{last_item.fields.price|cents_to_dollars}}</p>
            <p>Item Code:{{last_item.fields.product_id}}</p>
        </td>
    </tr>
</table>
{% endwith %}
<!-- end section -->

Live Example

This time we are only giving you one use case/example as creating these variables is easy, but these can be very difficult to implement without knowledge on Django or the Rejoiner templating language. Thus, we recommend using them with caution. As you go through the rest of this document, you'll see other cases where the {% with %} built in is used. Thus, this section is mostly meant to be an introduction so that other uses make more sense.

Exclude Filters

Exclude filters are powerful builtins part of the Rejoiner templating language. You will only be needing an exclusion filter when implementing several injection types at once. 

The exclude filter looks like so |exclude:data_set_to_exclude. This filter could be used in any combination of data_sets so it should cover any possible use case. 

Note: You can only use ONE exclude filter at a time. Campaigns with multiple filters will not send.

To use exclusions, we have to tell the application to exclude from the injected items. This is due to the fact that an email's content depends on a customer's session, and in order to avoid any repeats, we need to avoid duplicates on the fly.

So let's say that you wanted to inject a customer's last   viewed_items along  cart_items without any duplicates. To do this, you should follow the steps below: ZZ

1
First, we need to define what are injected items. In this case, we'll define injected items as the cart_items that are being shown in an email. We'll use the   {% with %} loop to define this like so:
{% with injected_cart_items=cart_items %}
2
Next, we need to add the loop tags and corresponding merge tags for injecting cart_items.
{% for cart_item in injected_cart_items %} Name: {{cart_item.fields_name}} {% endfor %}
3
Next, we need to add the corresponding loop and merge tags for viewed_items. However, we will be adding a conditional in case the customer doesn't have any viewed items.
{% if viewed_items %} {% for viewed_item in viewed_items %} Name: {{viewed_items.fields.name}} {% endfor %} {% endif %}
4
Next, we'll add the exclusion tag to the for loop tag in viewed_items
{% for viewed_item in viewed_items|exclude:injected_cart_items %}
5
(Optional) Next, we'll define the number of viewed items to display using the slide method
{% for viewed_item in viewed_items|exclude:injected_cart_items|slice:":3" %}
6
Finally, we'll close our variable and the entire condition
{% endwith %}

Example Usage **

<!-- start section and define injected items -->
{% with injected_items=cart_items %}

<!-- inject cart items -->
{% for cart_item in injected_items %}
<table>
    <tr>
        <td>
            <p>Name: {{cart_item.fields_name}}</p>
        </td>
    </tr>
</table>
{% endfor %}
<!-- end injected items -->

<!-- add conditional for viewed items --> 
{% if viewed_items %}
<table>
    <tr>
        <td>
        <!-- loop and inject viewed items while excluding injected cart items -->
        {% for viewed_item in viewed_items|exclude:injected_items|slice:":3" %}
            <div>Name: {{viewed_items.fields.name}}</div>
        {% endfor %}
        <!-- end loop and exclusion -->
        </td>
    </tr>
</table>
{% endif %}
<!-- end viewed items conditional -->

{% endwith %}
<!-- end section and definition -->

Exclusion filters have the following most common cases:

  • Case #1: You want to inject last viewed_items along cart_items without having these overlap*.
  • Case #2: You want to inject abandoned cart_items and product recommendations without having these overlap*.
  • Case #3: You want to inject last viewed_items and browse product recommendations without having these overlap*.
* By overlap we mean: having the same products show up in several sections.
Main Injected Item Defined as injected_items Secondary Injected Item Exclude Filter Usage
cart_items viewed_items {% for viewed_item in viewed_items|exclude:injected_items %}
cart_items top_sellers (recommendations) {% for product in products.top_sellers|exclude:injected_items %}
cart_items category_top_sellers (recommendations) {% for product in products.top_sellers|exclude:injected_items %}
cart_items purchased_together (recommendations) {% for product in products.purchased_togethers|exclude:injected_items %}
viewed_items browsed_category_top_sellers (recommendations) {% for product in products.browsed_category_top_sellers|exclude:injected_items %}
viewed_items viewed_together (recommendations) {% for product in products.viewed_together|exclude:injected_items %}
viewed_items top_sellers (recommendations) {% for product in products.top_sellers|exclude:injected_items %}

Math Filters

Math filters are useful to make live data calculations based on cart data that is passed to us. The most immediate uses are to add/subtract a certain dollar amount, and calculate a dollar amount from data. Below we'll show you both examples.

Math Filters Introduction

Math filters is a Python library that needs to be called into your creative in order for the filters to take effect. 

We call the library by adding the library using the tag {% load mathfilters %} right after the <body> HTML tag in our template.

The library provides the following basic filters:

Filter Description
sub Subtraction
Note: to subtract use the value of a number in cents. ie: $10.99 would be 1099, $5.99 would be 0599
mul Multiplication
Note: to multiply use the value of a number using decimal points. ie: 10.99 would be 10.99, 2 would be 2.0
div Division
Note: to divide use the value of a number using decimal points. ie: 10.99 would be 10.99, 2 would be 2.0
add Addition
Note: to add use the value of a number in cents. ie: $10.99 would be 1099, $5.99 would be 0599

Add/subtract a specific dollar amount

Let's say that you have a standard fee that is added to a customer's cart total. However, you'd like to show the subtotal of an abandoned cart without the fee and the fee amount separately in your campaign. In this case, we'd need to subtract the fee amount from the subtotal and then show the subtotal amount. To do so, you'll need to follow the steps below.

1
Load the math filters library
{% load mathfilters %}
2
Create a variable with the fee amount. You'll want to add the fee's value in cents.
{% with fee="0599" %}
3
Create a variable for the cart's total NEW value without the fee
{% with new_value=cart_data.value|sub:fee %}
4
Now that we have defined the variables, we can use the variable names to create merge tags. These will only be usable in the email where they are defined. 
To start we'll create a new merge tag based on the new_value variable that subtracts the fee. This merge tag should be:
{{new_value.cents_to_dollars}}
5
Then, inject the fee's value by creating a merge tag from the variable you created:
{{fee|cents_to_dollars}}
6
Lastly, you'll want to close the  {% with %} loops for each of variables you created. So in this example, we're closing two.
{% endwith %}
{% endwith %}

Example Usage **

<!-- cart subtotal section -->
{% load mathfilters %}
   {% with fee="0599" %}
      {% with new_value=cart_data.value|sub:fee %}
      <table>
         <tr>
           <td>
               <p>Subtotal: ${{new_value|cents_to_dollars}}</p>
           </td>
       </tr>
       <tr>
           <td>
               <p>Additional Fee: ${{fee|cents_to_dollars}}</p>
           </td>
       </tr>
       <tr>
           <td>
               <p>Cart Total: ${{cart_data.value|cents_to_dollars}}</p>
           </td>
       </tr>
      </table>
      {% endwith %}
   {% endwith %}
<!-- end section -->

Calculate dollar amount from data

Let's say that you want to show the dollar amount of a percentage discount. So if you wanted to show a customer the $ value of a 10% discount (for example) you can use the steps below as an example.

1
Load the mathfilters library
{% load mathfilters %}
2
Create a variable for the 10% discount
{% with discount="0.10" %}
3
Create a variable that will hold the formula for the cart's total value multiplied by the discount's percentage
{% with my_val=cart_data.value|mul:discount %}
4
Now that we have defined the variables, we can use the variable names to create merge tags. These will only be usable in the email where they are defined. To start we'll create a new merge tag based on the new_value variable that generates the discount's dollar value. This merge tag should be:
{{my_val|cents_to_dollars}}
5
If you wanted to subtract the dollar value of the discount on the total you can do so using:
{{cart_data.value|sub:my_val|cents_to_dollars}}
6
Lastly, you'll want to close the {% with %} loops for each of variables you created. So in this example, we're closing two.
{% endwith %}{% endwith %}

Example Usage **

<!-- cart discount section -->
{% load mathfilters %}
{% with discount="0.10" %}
{% with my_val=cart_data.value|mul:discount %}
<table>
    <tr>
        <td>
            <p>Your 10% Discount: ${{my_val|cents_to_dollars}}</p>
        </td>
    </tr>
    <tr>
        <td>
            <p>Your new subtotal: ${{cart_data.value|sub:my_val|cents_to_dollars}}</p>
        </td>
    </tr>
</table>
{% endwith %}
{% endwith %}
<!-- end section -->

Miscellaneous

There are times where you'd want to do certain things that may not be part of our standard templating language. Thus, we've created this section to help with that. These are the cases we'll guide you through:

Adding an invisible preheader

This allows you to create hidden preview text. We use invisible preheaders when we want the copy in the preview text to differ from the rest of the copy in the email.

1

Place the code snippet below right after the HTML's <body> tag

<!-- Invisible Preheader Text -->
<div style="display:none;font-size:0;line-height:0;max-height:0;mso-hide:all">Preheader</div>
<!-- end Invisible Preheader Text -->

Adding a "Tweetable" link in an email

This allows you to create links with sharable text that your customers can tweet straight from an email campaign.

1
This should always be the start of the href="" section on your link
https://twitter.com/intent/tweet?
2
The text that you want to tweet about goes inside here
Note that you must replace spaces with %20
text=I%20love%20Working%20With%20Rejoiner
3
You can add the twitter account to reference this way:
&via=rejoinerapp

The final result will be something like:

<a href="https://twitter.com/intent/tweet?text=I%20love%20Working%20With%20Rejoiner&via=rejoinerapp" target="_blank">SHARE ME</a>

Example: Tweet to share

Show the current year in the footer

This will allow you have the most up to date year in your templates. This is specially useful for the copyright section in your campaign's footer.

1
Simply insert the year tag {% now "Y" %} right at the section where it is needed.
&copy; {% now "Y" %} My Company, Inc.

Still need help? Contact Us Contact Us