{{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 == 'dancer' %}
  You are invited to dance baby dance.
{% endif %}

Output:

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

You are invited to dance baby dance.

unless

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

Input:

{% unless profession == 'dancer' %}
  You are not invited to dance baby dance.
{% endif %}

Output:

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

You are not invited to dance baby dance.

elsif/else 

More conditions within if and unless.

Input:

<!-- If profession = 'actor' -->
{% if profession == 'dancer' %}
  You are not invited to dance baby dance.
{% elsif profession == 'actor'%}
  You should go to Hollywood.
{% 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 Hollywood.

case/when 

Switch statement.

Input:

<!-- If profession = 'actor' -->
{% case profession == 'dancer' %}
  {% when 'dancer' %}
    You are not invited to dance baby dance.
  {% when 'actor' %}
    You should got to Hollywood.
  {% 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 Hollywood.

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 }}! <!-- first_name is empty-->

Output:

Hi there!

append

Attaches two strings.

Input:

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

Output:

Apple Inc.

Did this answer your question?