Conditional Merge Tags

How do I use conditional merge-tags (variables) in my emails ?

Guide to write Dynamic content email in SmartReach.io

{{merge_tags}}achieve personalization by replacing the merge tag with the information personal to a prospect. In {{something}}, something is the name of a column in prospect’s data. Examples include {{first_name}}, {{profession}}, {{Experience}}etc.

Dynamic content emails are written by applying logic on merge tags. When inside logic statements names of the columns must be used instead of whole merge tags. This guide is a collection of syntax used in writing Dynamic content email from SmartReach.io

Operators

==  equals 
!=  does not equal
or  logical or
and logical and

Control Flow

Logic that decides content in DCE can be written using these conditions

If

If a certain condition is true then add the content block.

Input:

{% if profession == 'marketer' %}
  You are invited to DreamForce.
{% endif %}

Output:

If the prospect’s profession is ‘Marketer’ then the following content will be added to email.

You are invited to DreamForce.

unless

unless is opposite of if — if a certain condition is false then add the content block.

Input:

{% unless profession == 'Marketer' %}
  You are not invited to DreamForce.
{% endunless %}

Output:

If the prospect’s profession is ‘dancer’ then the following content will be added to email.

You are not invited to DreamForce.

elsif/else

More conditions within if and unless.

Input:

{% if profession == 'Marketer' %}
  You are not invited to DreamForce.
{% elsif profession == 'Sales Development Rep'%}
  You should go to SaaSSales.
{% else %}
  Tell me your profession.
{% endif %}

Output:

If the prospect’s profession is ‘actor’ then the following content will be added to email.

You should go to SaaSSales.

case/when

Switch statement.

Input:

{% case profession %}
  {% when 'dancer' %}
    You are not invited to DreamForce.
  {% when 'Sales Development Rep' %}
    You should got to SaaSSales.
  {% else %}
    Tell me your profession.
{% endcase %}

Output:

If the prospect’s profession is ‘actor’ then the following content will be added to email.

You should go to SaaSSales.

Comments

Comments are important to make sense of your DCE after a while. Write comments this way

Input:

Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.

Output:

Anything you put between tags
is turned into a comment.

Raw

Raw temporarily disables merge tags. This is useful when your intended message contains flower brackets viz. “{{” “}}”

Input:

{% raw %}
  How are you {{first_name}}
{% endraw %}

Output:

How are you {{first_name}}

contains

Contains checks for the presence of sub string in the given string.

Input:

{% if first_name contains 'Peter' %}
  Your first name is Peter.
{% else %}
  Your first name is not peter.
{% endif %}

Output:

If the prospect’s first name contains peter.

Your first name is Peter.

capitalize

Capitalizes the first character of the string.

Input:

{{ "awesome" | capitalize }}
{{ first_name | capitalize }}<!-- first_name = 'mickey mouse' -->

Output:

Awesome
Mickey mouse

Default

Allows you to specify a fallback in case a value doesn’t exist. default will show its value if the left side is nil, false, or empty.

Input:

Hi {{ first_name | default:'there' }}!

Output:

Hi there!

append

Attaches two strings.

Input:

{{ company | append: " Inc." }}<!-- company = Apple -->

Output:

Apple Inc.

Nil

returns true when value of a string is null

{% if company == nil %} 
Hey 
{% else %}
Hey {{company}}
{% endif %}

output

Hey (if the value of a string is null or empty)