The following examples will show you some of the most common use-cases of conditions. Let's begin with some basic theory.
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" ...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.
== ... 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
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.
[% 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 -%]
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.
[% 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 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 -%]
Use different text color based on recipient gender.
<span class="color:#[% IF recipient.GENDER == 'F' -%]c40a80[% ELSE -%]0a59c4[% END -%]">Thank you!</span>
Recipient with "yes" in CUSTOM1 and "666" in CUSTOM2 fields will receive different content than the rest of recipients.
[% IF recipient.CUSTOM1 == 'yes' && recipient.CUSTOM2 == '666' -%] Congratulations! You are a winner! [% ELSE %] We are sorry, better luck next time! [% END -%]
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.
[% email = recipient.EMAIL -%] [% 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 -%]
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.