Sub topic 1
Merge Tags Versus Dynamic Content: What Personalisation Means
Prerequisites
This chapter assumes you have:
- Sent at least one campaign from an email platform.
- A working idea of contacts, lists and fields, such as first name or email address.
- Optionally, basic HTML email structure. It helps but is not required.
Examples use Liquid-style syntax. Other platforms use different delimiters, and the chapters that follow note the differences.
The working model
An email platform stores one template and one record of data per contact. At send time a rendering engine combines the template with each contact's record. The result is one finished message per recipient.
Personalisation covers two different mechanisms in this process: merge tags and dynamic content.
Merge tags: swapping values
A merge tag is a placeholder that the engine replaces with a field value. It changes the words in the email but not its structure.
Hi {{ customer.first_name | default: "there" }},
Thanks for being with us.Here customer.first_name is the field. The default filter supplies "there" when the field is empty or missing. Tag and field names vary by platform.
Dynamic content: changing what appears
Dynamic content uses data to decide which parts of the email appear. A part can be shown, hidden or repeated. The usual tools are conditional logic and loops.
{% if customer.plan == "pro" %}
Your Pro plan includes priority support.
{% elsif customer.plan == "free" %}
Upgrade to Pro to get priority support.
{% else %}
Explore our plans.
{% endif %}Two contacts can receive emails with different paragraphs, and even different calls to action, from the same template. The else branch covers contacts whose plan is unknown.
Comparing the two
| Row | Merge tag | Dynamic content |
|---|---|---|
| What it does | Inserts a value | Shows, hides or repeats content |
| Typical logic | None, or a filter such as `default` | `if`/`elsif`/`else`, `for` |
| Changes email structure | No | Yes |
| Main risk | Blank or badly formatted value | Wrong branch, or no branch matches |
Most real emails use both. A merge tag greets the reader by name, and a conditional block selects the offer.
Common errors
- No fallback. If
first_nameis empty and the tag has no default, the email reads "Hi ,". Always decide what the message says when data is missing. - Using logic where a tag is enough. Wrapping a single value in an
ifblock adds maintenance cost and nothing else. - No
elsebranch. A conditional with no matching branch renders nothing, so some contacts see a gap. - Assuming one syntax. Tag delimiters and filter names differ between platforms, so copying a snippet from one to another often fails or prints the raw tag.
- Previewing only complete contacts. A test contact with every field filled in hides most of these failures.
Rendering it yourself
You can see the same behaviour outside a platform. This Jinja2 example uses a fallback for an empty name. It also uses StrictUndefined, which raises an error when a field such as plan is missing instead of silently sending a blank.
from jinja2 import Environment, StrictUndefined
env = Environment(undefined=StrictUndefined)
template = env.from_string("Hi {{ first_name | default('there', true) }}, your plan is {{ plan }}.")
print(template.render(first_name="", plan="Pro"))
try:
template.render(first_name="Sam")
except Exception as error:
print(type(error).__name__)The first call prints Hi there, your plan is Pro. The second prints UndefinedError. The true argument makes default also replace empty strings, not only undefined values.
Exercise
A template contains Hi {{ customer.first_name }} followed by an if block that shows a discount only to contacts with customer.plan == "free". Which part is a merge tag, which part is dynamic content, and what should you add so a contact with no name and no plan still gets a sensible email?
Show answer
{{ customer.first_name }} is the merge tag, and the if block is dynamic content. Add a fallback to the tag, for example | default: "there". Add an else branch to the conditional so contacts with an unknown plan see generic content.