What is dynamic email content?

Dynamic email content allows you to tailor your email messages to the interests of each subscriber. There are a lot of different variables that you can pull into your messages, like subscribers' geographic location and their personal information. Content that is more relevant to subscribers often translates into increased engagement in terms of opens, clicks, and conversions.

Where can I use dynamic email content?

You can make use of dynamic email content anywhere in the AWeber message editor, including the subject line.

How do I write dynamic email logic?

In order to code for dynamic email content in your messages, you would have to include the logic tags below. 

{{ ... }} Print the value of a subscriber variable
Hello {{ subscriber.name }}
{% ... %} Evaluate an expression
{% if subscriber.signup.city == 'Philadelphia' %}
Local deals in Philly!
{% endif %}
{# ... #} Write comments in your message that are not seen by your subscribers.
{# This is a hidden comment. #}
{% raw %} Markup within the raw tag will not be evaluated as a variable or statement.
Here is how I personalize my email greeting:
{% raw %}
Hello {{ subscriber.first_name }}.
{% endraw %}

 

Operators

Operators help you display specific content if certain conditions are met. If the first condition outlined by the "if" operator is not met, then the system will look to another condition based on the "elif" operator. If neither condition is met, then the system will look to the content with the "else" operator.

 

If you have multiple conditions, the system will display the content based on the "and" or "or" operator.

 

if Display message content IF the statement is true.
{% if subscriber.custom_field['pet'] == 'dog' %}
Save 20% dog food!
{% endif %}
elif If the first condition isn't met, evaluate another condition.
{% if subscriber.custom_field['pet'] == 'dog' %}
Save on dog food!
{% elif subscriber.custom_field['pet'] == 'cat' %}
Save on cat food!
{% endif %}
and If both conditions are met, display message content.
{% if 'pet-dog' in subscriber.tags and 'grooming' in subscriber.tags %}
Get 25% off dog grooming this week.
{% else %}
Save 10% on pet supplies this week.
{% endif %}
or If one of the conditions is met, display message content.
{% if 'puppy' in subscriber.tags or 'dog' in subscriber.tags %}
Save on dog food!
{% else %}
Save on pet food!
{% endif %}
else Display the following content to subscribers that did not meet any of the conditions above.
{% if subscriber.custom_field['pet'] == 'dog' %}
Save on dog food!
{% elif subscriber.custom_field['pet'] == 'cat' %}
Save on cat food!
{% else %}
Save on pet food!
{% endif %}

 

Comparison Operators

Comparison operators work in conjunction with the operators above.

== equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to

 

Filters

Filters help you customize the content by capitalizing specific letters, displaying fallback content when the subscriber doesn't have a value, and displaying a random option from a set of choices.

upper() Converts each character in a string to uppercase
{{ "hello there" | upper() }}
HELLO THERE
lower() Converts each character in a string to lowercase
{{ "HELLO THERE" | lower() }} 
hello there
capitalize() Capitalizes the first word in a string
{{ "hello there" | capitalize() }}  
Hello there
title() Capitalizes each word in a string
{{ "hello there" | title() }} 
Hello There
default() Provides a fallback if the variable has no value assigned
Dear {{ subscriber.first_name or "friend" }},
Dear friend,
Other common greeting format optimizations.
truncate() Returns a truncated version of a string
{{ "The quick brown fox jumps over the lazy dog" | truncate(20) }}
The quick brown fox...
wordwrap() Wraps a string of text to a given width.
{{ "Chocolate bar soufflé dessert. Brownie tiramisu gummi bears donut donut tiramisu halvah sesame snaps tart. Cheesecake fruitcake chupa chups ice cream." | wordwrap(width=20, break_long_words=False, wrapstring="
", break_on_hyphens=True)}}

The string wraps when the next word doesn't fit on the line. In this example, the line width is set to only 20 characters in length.

Chocolate bar
soufflé dessert.
Brownie tiramisu
gummi bears donut
donut tiramisu
halvah sesame snaps
tart. Cheesecake
fruitcake chupa
chups ice cream.
replace() Return a copy of a string with all the occurances of a substring replaced with a new one.
{{ "The quick brown fox jumps over the lazy dog" | replace("fox", "rabbit") }}
The quick brown rabbit jumps over the lazy dog
first() Returns the first item of a sequence
{{ ['Apples', 'Oranges', 'Grapes'] | first() }}
Apples
last() Returns the last item of a sequence
{{ ['Apples', 'Oranges', 'Grapes'] | last() }}
Grapes
unique() Returns a unique set of items in a sequence
{% set colors = ['red', 'blue', 'red', 'orange', 'blue', 'white'] %}
{% for item in colors | unique() %}
  {{ item }}
{% endfor %}
red
blue
yellow
orange
white
count() Returns the number of items in a list
{{ ['a','b','c','d','e','f'] | count() }}
6
sum() Returns the sum of a sequence
{{ [12, 4, 545, 714, 332, 451, 975, 8, 1, 34, 342] | sum() }}
3418
min() Returns the smallest item in a list
{{ [12, 4, 545, 714, 332, 451, 975, 8, 1, 34, 342] | min() }}
1
max() Returns the largest item in a list
{{ [12, 4, 545, 714, 332, 451, 975, 8, 1, 34, 342] | max() }}
975
random() Select a random item from a set of choices
{{ ['Apples', 'Oranges', 'Grapes'] | random() }}
Grapes

join()

Returns a string of items joined by a separator.
{{ ['Apples', 'Oranges', 'Grapes'] | join(" | ") }}
Apples | Oranges | Grapes

select()

 

Filter a sequence to items matching the criteria provided.
{% for number in [1, 2, 3, 4, 5, 6, 7] | select("odd") %}
{{ number }}
{% endfor %}
1
3
5
7

 

Other examples include:

{{ numbers | select("odd") }}
{{ numbers | select("even") }}
{{ numbers | select("divisibleby", 3) }}
{{ numbers | select("lessthan", 42) }}
{{ strings | select("equalto", "mystring") }}

random_number()

Returns a random number between two values.
{{ random_number(1,500) }}
371

round()

Round a number to a given number of decimal places
{{ 34.2374 | round(2) }}
34.24

now()

Returns the current date and time.

{{ now | date_format('MM/DD/YYYY') }}
01/26/2021

hash_md5

Returns an MD5 hashed value

{{subscriber.email | hash_md5}}
d25d937d5ba2b799ad482aabca11c660

 

Date Formatting Options

  Token Example and Output
Year YYYY
The current year is {{ now | date_format('YYYY') }}

The current year is 2021

  YY
The current year is '{{ now | date_format('YY') }}

The current year is '21

Month

MMMM

The month is {{ now | date_format('MMMM') }}

The month is April

 

MMM

The month is {{ now | date_format('MMM') }}

The month is Apr

 

MM

The month is {{ now | date_format('MM') }}

The month is 04

 

M

The month is {{ now | date_format('M') }}

The month is 4

Day of the Year

DDDD

Today is day number {{ now | date_format('DDDD') }}

Today is day number 095

 

DDD

Today is day number {{ now | date_format('DDDD') }}

Today is day number 95

Day of the Month

DD

Day {{ now | date_format('DD') }} of the month.

Day 05 of the month.

 

D

Day {{ now | date_format('D') }} of the month.

Day 5 of the month.

 

Do

{{ now | date_format('D') }} day of the month.

5th day of the month.

Day of Week

dddd

Today is {{ now | date_format('dddd') }}.

Today is Monday.

 

ddd

Today is {{ now | date_format('ddd') }}.

Today is Mon.

 

d

Today is day {{ now | date_format('d') }} of the week.

Today is day 1 of the week.

Hour

HH

The hour is: {{ now | date_format('HH') }}.

The hour is: 04.

Possible values: 00, 01, 02 ... 23, 24

 

H

The hour is {{ now | date_format('H') }}.

The hour is: 4.

Possible values: 0, 1, 2 ... 23, 24

 

hh

The hour is: {{ now | date_format('hh') }}.

The hour is 04

Possible values: 01, 02, 03 ... 11, 12

 

h

The hour is: {{ now | date_format('h') }}.

Possible values: 1, 2, 3 ... 11, 12

AM / PM

A

We will begin at {{ now | date_format('h A') }}.

We will begin at 2 PM.

 

a

We will begin at {{ now | date_format('h a') }}.

We will begin at 2 pm.

Minute

mm

Possible values: 00, 01, 02 ... 58, 59
 

m

Possible values: 0, 1, 2 ... 58, 59
Second

ss

Possible values: 00, 01, 02 ... 58, 59
 

s

Possible values: 0, 1, 2 ... 58, 59
Date Shift

Shift the date into the future or the past.

{{ now | date_format(fmt='YYYY-MM-DD', shift_days= -10) }}

The above example will print the date for "10 days ago".  

View additional documentation and examples.

For more information on dynamic email content, and the different types of variables that you can include when coding for dynamic email content, check out the articles below:

Have more questions? Submit a request