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.
[% ELSE -%]content/commands to be processed if condition IS NOT met[% END -%]
Each condition starts with: [% IF "something" ...is 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:
[% 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:
[% 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.
[% 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:
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:
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 seznam.cz, email.cz, post.cz, spoluzaci.cz, stream.cz, or firmy.cz. Other recipients will not see anything.
Condition used:
[% IF email.match('seznam.cz') || email.match('email.cz') || email.match('post.cz') || email.match('spoluzaci.cz') ||
email.match('stream.cz') || email.match('firmy.cz') -%]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.