Skip to content

How to Show Conditional Text Only to Some Recipients in Mail Merge

A condition shows a sentence, a paragraph or an attachment only to the people it’s meant for. Mail Merge checks a column in each row to decide what to include. For example, customers with a value in the Discount % column read “Your 10% discount is applied.” Everyone else gets the same email without that line.

A filter changes how a value from your sheet appears in the email, without hiding any text. For example, Hi {{First Name}}, becomes Hi , when the First Name cell is empty. Write Hi {? {{First Name}} | default: "there" ?}, instead, and the email says “Hi there,” for that row. Filters can also fix capital letters, format a date or do arithmetic.

Tom at Becker Bikes emails an order confirmation to each customer. His sheet has one row for each order:

First Name Email Address Order # Bikes Discount % Store
Angus angus@example.com 1042 2 10% Berlin
Daniel daniel.okafor@example.net 1043 1 Munich

He writes the email once:

Hi {{First Name}},
Thanks for your order.
{% if {{Discount %}} != "" %}
Your {{Discount %}} discount is applied.
{% endif %}
{% if {{Store}} == "Berlin" %}
Collect your order from our Berlin store on Torstrasse.
{% else %}
We will deliver your order to your door.
{% endif %}

Angus reads Your 10% discount is applied and Collect your order from our Berlin store on Torstrasse. Daniel has no discount and his store is Munich, so he reads only We will deliver your order to your door.

  1. Go to Extensions > Mail Merge with Attachments > Open Mail Merge, open your campaign and move to the Template step.

  2. Click before the text that only some people should see and type the opening tag, with the column title as a merge field:

    {% if {{Store}} == "Berlin" %}
  3. Click after that text and type the closing tag:

    {% endif %}
  4. Click Send Test Email and send the email to yourself. The test uses row 2 of your sheet, so change the value in that row to check both results.

Every {% if %} needs its own {% endif %}. Type the tags with straight quotes. Leave the tags as plain text, because a tag that is partly bold or coloured stops working.

You write The text shows when
{% if {{Store}} == "Berlin" %} The Store cell is Berlin. Capital letters must match.
{% if {{Store}} != "Berlin" %} The cell is anything else, or empty
{% if {{Discount %}} != "" %} The Discount % cell is not empty
{% if {{Discount %}} == "" %} The cell is empty
{% if {{Bikes}} > 1 %} The Bikes cell is a number above 1
{% if {{Bikes}} >= 2 and {{Store}} == "Berlin" %} Both are true
{% if {{Store}} == "Berlin" or {{Store}} == "Munich" %} Either is true
{% if {{Store}} contains "Ber" %} The cell has those letters anywhere in it

Put text in quotes, but not numbers. A condition reads the text of the cell, so a cell in bold or in colour still matches.

To choose between more than two results, add {% elsif %}:

{% if {{Store}} == "Berlin" %}
Collect your order from Torstrasse.
{% elsif {{Store}} == "Munich" %}
Collect your order from Sendlinger Strasse.
{% else %}
We will deliver your order to your door.
{% endif %}

The Scriptlets Reference lists every tag, such as unless, case and loops.

Put an Embed File marker inside a condition, and Mail Merge attaches the file only when the condition is true. Tom sends a fleet care guide to customers who bought more than one bike:

{% if {{Bikes}} > 1 %}
{{Embed File, Fleet Care Guide.pdf}}
{% endif %}

Angus bought 2 bikes and gets the PDF. Daniel bought 1 and gets no attachment. Conditions work the same way for the other Embed markers, such as a QR code or a picture.

Where Example
Message {% if {{Store}} == "Berlin" %}Collect your order.{% endif %}
Subject Order {{Order #}}{% if {{Bikes}} > 1 %}: your bikes are ready{% endif %}
Sender name {% if {{Store}} == "Berlin" %}Becker Bikes Berlin{% else %}Becker Bikes{% endif %}

Mail Merge doesn’t read conditions and filters in Send to, CC, BCC or Reply-to.

  • Capital letters and spaces count. Berlin does not match berlin or Berlin with a space after it.
  • A number with a comma or a currency sign is text. You can’t compare 1,250.00 or $25 with > or <. Keep a column of plain numbers, like 1250, for the condition.
  • An empty cell is not “false”. {% if {{Discount %}} %} is true for every row. Compare with "" to check for an empty cell.
  • Mail Merge never reads a value from your sheet as a tag. If a cell holds {% if %}, the email shows that text.
  • {% include %}, {% render %} and {% layout %} are not available.

The status column shows “Scriptlet error in the template”

Section titled “The status column shows “Scriptlet error in the template””

A tag in your template has a mistake, so Mail Merge didn’t send the email for that row. If Mail Merge can’t read the template at all, the campaign stops at the first row.

The rest of the message says what to fix:

The status says Check this
tag {% if … %} not closed An {% if %} has no {% endif %} after it.
tag "endif" not found An {% endif %} has no {% if %} before it.
expected "|" before filter The tag has curly quotes or formatted text, or its closing %} is missing a character. Type the tag again as plain text.
tag "include" not found The tag is not available in Mail Merge.

Fix the template, then run the campaign again. Mail Merge sends the rows with an error on the next run.

There is a space between { and %, so Mail Merge reads the tag as ordinary text. Type the tag again as {% if … %}, with no space after the first brace or before the last one.

Check these in order:

  1. Does the value in the quotes match the cell, with the same capital letters and no extra space?
  2. Is the text in quotes, like "Berlin"? Without quotes, the condition is never true and Mail Merge shows no error.
  3. For > or <, does the cell hold a plain number with no comma, currency sign or unit?