ResourcesKnowledge Base

Conditions & operators

You can use the IF/ELSIF/ELSE logical conditions wherever you want to apply any personalization or ensure that the automated email is up-to-date.

The following examples will show you some of the most common use-cases of conditions. Let's begin with some basic theory.

Creating a condition

IF / ELSIF / ELSE conditions are used to define "what if" - if condition is met, or not.

[% IF "condition" -%]content or further templating logic to be processed/returned if condition IS met
[% ELSE -%]content/commands to be processed if condition IS NOT met[% END -%]

Each condition starts with: [% IF "something" equal to, contains, is not equal to ... "something" -%] and ends with: [% END -%]. In creating the condition, you can use content merge tags, content from data sources, as well as custom variables and structures passed through the API.

Supported operators:

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

! ... empty
variable.match('string') ... contains string (supports regular expressions)

&& ... AND operator
|| ... OR operator

Personalized salutation

Objective of the condition:

If the gender of the recipient is male – display "Dear Sir",
If the gender of the recipient is female – display "Dear Madam",
If no gender is specified – display "Dear customer",
If the gender is stated and at the same time the name is given – display last name in the salutation.

Condition used:

[% IF recipient.GENDER == 'M' -%]Dear Sir
[% ELSIF recipient.GENDER == 'F' -%]Dear Madam
[% ELSE -%]Dear customer[% END %]
[% IF recipient.GENDER !='' && recipient.LAST_NAME !='' -%][LAST_NAME],[% ELSE -%],[% END -%]

Message in recipient's language

Objective of the condition:

The recipient record has a language code stored in the field CUSTOM25. This language should be used for communication with the recipient. The values are "de" for german, "es" for spanish. English (default language) will be used for all others.

Condition no.1 used:

[% IF recipient.CUSTOM25 == 'de' -%]Interessieren Sie sich nicht für unseren Newsletter? Klicken Sie hier, um sich abzumelden
[% ELSIF recipient.CUSTOM25 == 'es' -%]No te interesa nuestro boletín? Haga clic para cancelar la suscripción.
[% ELSE -%]Not interrested in our newsletter? Click to unsubscribe [% END -%]

Condition no.2 used:

Condition used in the template to use different content areas in the body of an email depending on recipient's language.

[% IF recipient.CUSTOM25 == 'de' -%][CONTENT2]
[% ELSIF recipient.CUSTOM25 == 'es' -%][CONTENT3]
[% ELSE -%][CONTENT][% END -%]

Different content

Objective of the condition no.1:

Use different text color based on recipient gender.

Condition used:

<span class="color:#[% IF recipient.GENDER == 'F' -%]c40a80[% ELSE -%]0a59c4[% END -%]">Thank you!</span>

Objective of the condition no.2:

Recipient with "yes" in CUSTOM1 and "666" in CUSTOM2 fields will receive different content than the rest of recipients.

Condition used:

[% IF recipient.CUSTOM1 == 'yes' && recipient.CUSTOM2 == '666' -%]
Congratulations! You are a winner!
[% ELSE %]
We are sorry, better luck next time!
[% END -%]

Objective of the condition no.3:

Show a specific content to all recipients with mailbox on domains,,,,, or Other recipients will not see anything.

Condition used:

[% email = recipient.EMAIL -%]
[% IF email.match('') || email.match('') || email.match('') || email.match('') ||
email.match('') || email.match('') -%]Find out how not to miss your news and discounts![% END -%]

Where can you use it?

And where to insert the condition? You can insert the condition into the content style editor or work with it in HTML code as with plain text. However, the conditions are managed by the template language and thus primarily belong to the templates. In the case of use directly in the editor, it is necessary to think about a valid notation in the HTML code.

In case you need help with creating your condition, don't hesitate to contact us, we will be happy to help.