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 -%]
Every condition start with: [% IF "something" ...is 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.
== ... 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
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.
[% 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 -%]
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.
[% 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 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 -%]
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 email addresses in domains seznam.cz, email.cz, post.cz, spoluzaci.cz, stream.cz, or firmy.cz. Receivers from other domains won't 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') -%] Do you have your email at Seznam? Find out how not to miss your news and discounts![% END -%]
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.