Conditional blocks allow your designs to have parts that are not sent or shown to all recipients. Only those for whom some condition is met will see that part of the message. This is an efficient alternative to producing a custom design for each small group of contacts who need to be shown different content:
Where to use them
You can use conditional blocks in 5 places:
- HTML designs
- SMS designs
- Email subjects
- Email sender name
- Templates
Conditional Blocks - the basics with examples
Conditional Blocks with the = operator
Conditional Blocks with the != operator
Conditional Blocks using comparison operators
Conditional Blocks using LIKE and NOT LIKE
Conditional Blocks based on a filter
List of all operators
Tips and good practices
Where to find them?
Splio has shortcuts to the most commonly used conditional blocks. To find them, go to the email design editor, e.g., by clicking the "New Email" button (1), then select the "HTML Editor" tab (2) and (3) Functions.
Use the "Functions" button (3) and select "Conditional blocks" (4) from the "Tools" menu on the left.
Click the conditional block you need and confirm with the "Select" button. The conditional syntax will be inserted into your code.
Inserting conditional blocks using Message Builder
You can insert conditional blocks when creating emails with Message Builder. This can be done in two ways:
- By inserting one or several text blocks including the syntax (this option is relevant if you have only text to display in the block)
- By inserting an HTML block including the syntax (this option is preferred if you wish to set the size and ratio of an image in a block or loop)
Inserting your block in one single text block (red arrow shows where to find the Functions menu with the ready syntaxes).
Example of a conditional block used in different blocks
Conditional Blocks - the basics with examples
Conditional blocks consist of one or more conditions contained between {SPLIO IF}
and SPLIO ENDIF}
statements. The second and next conditions must be introduced by the {SPLIO ELSEIF}
statement.
Conditions are always evaluated in the order they are written. As soon as a condition is found true, the content between it and the next {SPLIO . . . }
statement becomes part of the current message, and all other conditions in the block are skipped.
The content between the {SPLIO ELSE}
and {SPLIO ENDIF}
statements is included by default when no conditions are met.
This is best illustrated in the examples below. All examples are broken into multiple lines to make them easier to read. Note, however, that you may have to write some conditional blocks in just one line, e.g., for email subjects.
Conditional Blocks with the = operator
We are going to explore conditional blocks with examples using the "equal to" operator. You can use it to include specific content if, and only if, a field value is equal to the value in the condition.
{SPLIO IF $gender$ = "male"}
Dear Mr.
{SPLIO ELSE}
Dear Ms.
{SPLIO ENDIF}
If the $gender$ field for the current contact contains the value "man", write "Dear Mr." and the contact's last name. Otherwise do nothing.
{SPLIO IF $gender$ = "male"}
Dear Mr.
{SPLIO ELSEIF $gender$ = "female"}
Dear Ms.
{SPLIO ENDIF}
Explanation:
- If the $gender$ field for the current contact contains the value "man", write "Dear Mr." and the contact's last name, then continue after the ENDIF statement.
- If the $gender$ field value is "woman" instead, write "Dear Ms." and her last name.
{SPLIO IF $gender$ = "male"}
Dear Mr.
{SPLIO ELSEIF $gender$ = "female"}
Dear Mr.
{SPLIO ELSE}
Dear Client
{SPLIO ENDIF}
Explanation:
- If the value of the $gender$ field for the current contact equals "man", write "Dear Mr." and the contact's last name, then continue after the ENDIF statement.
- If the $gender$ field value is "woman", write "Dear Ms." and the contact's last name, then continue after the ENDIF statement.
- If the $gender$ field contains anything else, write "Dear Client,".
Conditional Blocks with the != operator
The "not equal to" operator is the reverse of the previous one. Conditions using "!=" are always met except when the field contains the given value.
{SPLIO IF $firstname$ != ""}
$firstname$, an incredible offer for you!
{SPLIO ELSE}
Dear client, an incredible offer for you!
{SPLIO ENDIF}
Explanation:
- Splio checks the $firstname$ field for the current contact. If the field is not empty, Splio writes the contact's first name and the words "an incredible offer for you!"
- Otherwise, Splio writes "Dear Client, an incredible offer for you!"
Conditional Blocks using comparison operators
These operators – ">" (greater than), ">=" (greater or equal), "<" (less than), "<=" (less or equal) – are used mostly with numbers. For example, they allow you to include different content for contacts from different age or spending groups.
{SPLIO IF $age$ >= "60"}
[include a special content for seniors]
{SPLIO ELSE}
[include a special content for yuonger]
{SPLIO ENDIF}
Explanation:
- If the value of the $age$ field for the current contact is 60 or more, write the invitation to the line of cosmetics for seniors.
- Otherwise, write an invitation to a daily care cosmetics line.
Conditional Blocks using LIKE and NOT LIKE
With these operators, you can check if a field contains (or does not contain) a string of characters.
This way, if you have a field containing favorite products for each contact in your database, you can test if a specific product is present in this list with LIKE
(or absent from, with NOT LIKE
).
{SPLIO IF $email$ LIKE "%gmail%"}
[Content for Gmail]
{SPLIO ELSE}
[Generic content]
{SPLIO ENDIF}
Explanation:
- Splio checks if the $email$ field value for the current contact contains the character string "gmail" in it.
- If so, the special content optimized for this email provider is used.
- Otherwise, the generic content is included in the message.
Conditional Blocks based on a filter
If you have segments (filters or groups) in your database that divide your customers into groups, e.g., according to loyalty program tiers or spending characteristics, you may want to include special content addressed to contacts from each segment using the IN SEGMENT
keyword.
The IN SEGMENT
keyword must be followed by the numerical ID of a contacts filter or group. You cannot use sales or loyalty filters because they contain different data and so will never match. The image below shows where you can find the ID in the list of filters.
The following example assumes that you have these 3 segments:
- ID = 22 with contacts to VIP members of your loyalty program,
- ID = 26 with regular members of this program,
- ID = 16 with contacts who are potential members of the program (prospects)
{SPLIO IF IN SEGMENT 22}
[include a special offer for VIP customer]
{SPLIO ELSEIF IN SEGMENT 26}
[include a special offer for regular customer]
{SPLIO ELSEIF IN SEGMENT 16}
[include a special offer for prospects]
{SPLIO ELSE}
[include anything else]
{SPLIO ENDIF}
Explanation:
- If the current contact is present in segment 22 (by segment ID), include VIP content, then skip to the
ENDIF
statement. - If the current contact is present in segment 26, include regular member content, then skip to the
ENDIF
statement. - If the current contact is present in segment 16, include content for prospective members, then skip to the
ENDIF
statement. - If you are here, it means that neither of the above conditions was met. Do nothing.
- Continue producing the message after the conditional block.
List of all operators
You can find all operators used to evaluate relationships between variables (e.g., field values) and values in this table:
OPERATORS | DESCRIPTION | EXAMPLE |
= | Equal to | $gender$ = "man" |
!= | Different to | $status$ != "inactive" |
> | Greater than (numerical values or dates) | $age$ > 18 |
< | Less than (numerical values or dates) | $age$ < 50 |
>= | Greater or equal | $age$ >= 35 |
<= | Less or equal | $age$ >= 24 |
LIKE "%value%" | Contains | $cellphone$ LIKE "%+33%" |
NOT LIKE "%value%" | Does not contain | NOT LIKE "@" |
LIKE must be used with the symbol % (before, after or both) + the value |
Tips and good practices
These are not rules but following them will help you avoid errors or just make your designs easier to read and analyze.
- Always separate the operators by blank space (
$var1$ > $var2$
, not$var1$>$var 2$
) - You cannot add conditional blocks by going through the WYSIWYG editor in Splio. You need to do it directly in the HTML file, use the HTML code editor or Message Builder.
- The conditional blocks always start with a
{SPLIO IF}
statement, and end with a{SPLIO ENDIF}
. - It is not possible to put one conditional block within another (this is called nesting). You need to use the syntax
{SPLIO IF} . . . {SPLIO ELSEIF} . . . {SPLIO ELSE} . . . {SPLIO ENDIF}
instead.
For ready to use conditional blocks, go to the Intro & Tutorial section > Ready to use blocks & loops > conditional blocks