Directives
Operators
These operators are used inside if statments and other ESL when making comparisons.
eq neq
Is equal to Is not equal to
{{ If ([Merge] eq "Value") }} {{ If ([Merge] neq "Value") }}
gt lt gte lte
Greater than Less than Greater than or equal to Less than or equal to
{{ If ([Merge] gt 5) }} {{ If ([Merge] lt 5) }} {{ If ([Merge] gte 5) }} {{ If ([Merge] lte 5) }}
in notin
Is in the list of supplied values Is not in the list of supplied values
{{ If ([Merge] in "Value 1", "Value 2", "Value 3") }} {{ If ([Merge] notin "Value 1", "Value 2", "Value 3") }}
all
If the test value matches all of the list of values
{{ If ("Value" all [Merge 1], [Merge 2], [Merge 3]) }}
If
The if statement is used to show/hide certain information for a person depending on the value of field. This allows one person to see one thing, but another to see something completely different.
Basic structure
If statements always follow this basic structure:
{{ If( conditional statement goes here ) }}
Show this text
{{ Else }}
Otherwise show this text
{{ EndIf }}The {{Else}} section is optional:
{{ If( conditional statement goes here ) }}
Show this text
{{ EndIf }}Note that if statements can only have two possible outcomes, i.e. a contact either matches the if condition, or they fall into the else group. You can nest if statements if you need to create more complex logic, or you can use a switch.
Conditional statements
The conditional statements usually contain three parts:
Left half you're comparing - often a merge field, but can be a static value
An operator - e.g. eq, neq
Right half you're comparing - often a static value, but can be a merge field
Remember that data types matter here, for example if your static value is a string then it will need to be wrapped in quotes.
You can see a few samples of different conditional statements below.
If a yes/no field is true (i.e. yes):
If a field is equal to a specific value:
If a field is not empty:
If a value is in the output from a list of merge fields:
If a field value exists in a list of values:
Examples
Show different content if city from database is Auckland:
Show different content if the contact doesn't have a first name in the database (note you could also do this with coalesce):
Show different content based on if a person's favourite fruit is in a list:
Show different content if city from database is Auckland, and if they live in the central city (nested if statements):
Switch
While an if statement can only ever have two outcomes (the contact either matches the condition or they don't) the switch allows you to have infinite different outcomes.
There are two ways to use a switch:
Provide a merge field and show a different result based on the value each contact has in that field
Provide individual conditional statements for each case
You can include as many cases as needed and can provide an optional default fallback for if none of the other cases are a match.
Providing a merge field
When providing a merge field the merge field is inserted at the top in the switch and each case simply contains the database value you want to show the content for.
Provide individual conditional statements
When providing individual conditional statements the switch is empty, and the conditional statements go against each case. This allows you to use more complex logic around when different cases are shown. They can even use different merge fields.
Note that if a contact matches multiple cases only the first one will be displayed.
Examples
Change out different messages based on what city a person has in their database field. If the value in their database field isn't "Auckland", "Wellington" or "Christchurch" then they will see the default case.
Use individual conditional statements to show different messages based on age. Using conditional statements in this case allows you to use greater than and less than operators so only three cases are needed. If simply providing a merge field you'd need to have a separate case for every possible age.
Coalesce
Coalesce is used to display only one non-blank value from a list of merge fields for a contact. Engage will look at the value of each merge field in the list one at a time in the order supplied until if finds one that has a value (i.e. is not null/blank), then it will output that value.
You can include as many merge fields as you want, and can optionally include a static value at the end to be displayed if all the merge fields are blank.
Example
Show a persons first name if you have it, if it's blank then show their salutation, and if that's blank too then just show "there":
Reverse Coalesce
Reverse coalese will output all values but only if all merge fields have a value (i.e. are not null/blank). If a single merge field is blank then nothing will be output. This is often useful for including conjunctions (e.g. "and") in a sentence but only when you actually have two values to join.
You can include as many merge fields and static values as you want, in the order you want them to be output.
Example
In this example if customer 2 name is blank then only "Hi Customer 1 Name" will be output, however if there is a customer 2 name then it say "Hi Customer 1 Name and Customer 2 Name". Note the space at the end of the "and" which is included in the brackets.
Literal
Sometimes you want to use square brackets "[]" or double curly braces "{{}}" for something other than ESL. If you try to do that normally however Engage will think that what you've entered should be a merge field and you will get an eror saying that the value could not be found.
This is where the {{ Literal }} statement comes in. Engage will leave alone any square brackets or double curly braces inside literal tags. This also means that any ESL you include inside literal tags will be ignored - so be careful where you use it.
Example
Ignore the CSS selector in style sheets (often selectors with square brackets are used in mobile styles):
Cast
If you have data in a field that isn't the correct field type, such as a number in a text field, then you can use cast to tell ESL to treat the field as a different field type. This allows you to make use of field type formatters to change the way your field outputs.
Between the open and end cast tags you will have access to a [Value] merge field that Engage will treat as the appropriate data type and on which the required formatter can be used.
Available data types are:
MobileNumber
WholeNumber
Decimal
Date
Time
YesNo
Text
UniqueIdentifier
There is also a cast function that is useful when stringing multiple functions together to perform a sequence of actions on the value before it is output (e.g. cast it as a date, add 1 month to that value, then output the result).
Example
In the example below there is a database field called "Purchase Price" but it was accidentally set up as a text field type instead of a decimal field. In order to format this field to output as a currency with a $ and two decimal places, we need to cast this field as a decimal. Now we can merge out the [Value] formatted with a (c) for currency.
Split
The split directive allows you to split a string of text into multiple parts by defining the character you would like to split on. You can then loop over the resulting items and format them as required.
The most basic syntax is:
However, there are additonal sections you can include that give you more control over the output:
The character can be whatever you like, for example you could break a sentence down into it's individual words by splitting on a space " ".
The [Item] merge field is where Engage will insert the output for each item in the split. [ItemIndex] will output a count (starting at 1) for the item currently being output.
Engage will look over the data from the merge field supplied and split it on the chosen character. If there is at least one item to output it will: include the header, then jump back and forth between inserting items and alternate items with a separator in between until it runs out, then output the footer.
Example
If you have a checkbox list on an Engage form this will be inserted into the database as a semi-colon separated list, e.g. "Chocolate; Lollies; Cake". Say however that when a person fills in this form that you want to send them a bullet list of their selected options. You could do the following:
Including the <ul> and </ul> in the header and footer respectively allows you to only include those tags when there is at least one item to output, i.e. when the person ticked at least one box on the form.
While
The while directive allows you to loop until a condition matches, at which point it will stop looping.
The most basic syntax is:
This also has access to additional sections however:
[ItemIndex] will output a count (starting at 1) for the item currently being output.
If your condition is never matched (i.e. it gets stuck in an infinite loop) then Engage will not output anything.
Example
This will output five paragraphs, each numbered in series, e.g. "This is item 2":
Last updated
Was this helpful?

