ResourcesKnowledge Base

Conditions & operators

The basic IF/ELSIF/ELSE conditions & operators are the key functions needed for any kind of variable content. Whether it's simple personalization or a more complex one, conditions are the key.

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 -%]

Every condition start with: [% IF "something" equal,matched,not equal... "something" -%] and ends with: [% END -%]. When creating a condition you can use the values available in content merge tags, content from data sources as well as custom variables and structures passed through API calls.

Supported operators:

== ... equal
!= ... not equal
< ... smaller than
<= ... smaller or equal
> ... larger than
>= ... larger or equal

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

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

Personalized greeting

Condition goal:

If recipient is a male - display "Dear sir",
If recipient is a female - display "Dear lady",
If recipient has no known gender - display "Dear customer",
If recipient has known gender and last name - display last name in the greeting.

Condition used:

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

Message in recipient's language

Condition goal:

The recipient record has a language code stored in field CUSTOM25. This language should be used for communication with the recipient. The values are "de" for german, "es" for spanish. All other recipients will default to english language.

Condition no.1 used:

[% IF recipient.CUSTOM25 == 'de' -%]Sie interessieren 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 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

Condition goal 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>

Condition goal 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 -%]

Condition goal no.3:

Show a specific content to all recipients with email addresses in domains,,,,, or Receivers from other domains won't see anything.

Condition used:

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

Where do I use it?

Do you wonder where to use your condition? Conditions can be entered in the editor or directly into the HTML code as if it was any other text content. Conditions are using our templating language and they should be primarily used in templates. In case of using the conditions within the content editor one must consider validity of the HTML code.

In case you need help creating your own conditions please feel free to contact us.