For the complete documentation index, see llms.txt. This page is also available as Markdown.

Variables

What are variables?

ESL allows you to create variables, which are like temporary merge fields, to store data for using multiple times in the content you're working on.

For example, you might need to use a switch statement to determine a value that needs to be output in an email for different contacts. If you were just outputting the value in one place, then placing the switch where you want the output to go would be simple.

But if you wanted to output that same value in two or more locations through the template, then you'd need to replicate your switch two or more times. Any changes to that switch would then be time consuming.

Instead this can be done with a variable - the switch could go at the top of the template which assigns the values to the variable. Then later in your email you can simply merge that variable out. This way there is only one switch statement to maintain if changes are needed.


Creating a variable

Variables names always starts with an @ sign. To merge out the value of a variable it should be wrapped in square brackets.

{{ Variable(@varname as "type") }}
    [@varname]
{{ EndVariable }}

You can only merge a variable between the Variable and EndVariable tags.

Types available are:

  • MobileNumber

  • WholeNumber

  • Decimal

  • Date

  • Time

  • YesNo

  • Text

  • UniqueIdentifier

Type is optional. If you don't set a type UbiQuity defaults to "Text".

You can define more than one variable at a time, however they must all have the same type.

Examples

Create a variable called Count, which is a WholeNumber, then merge that variable out. Note though that as we haven't assigned a value to the variable it will be null, and nothing will be output on the page.


Assigning a value to a variable

Variables aren't much use if you don't assign them a value. To assign a value to a variable you use Assign, and can use this in two different ways: either as a string or as a block.

String assigns

String assigns are useful when you want to just insert a simple value or line of text. They aren't ideal if your content contains quotes (as it can incorrectly close the ESL) and you can't use merge fields or track links inside the value. Note that UbiQuity will trim spaces on either side of your value with a string assign.

Block assigns

Block assigns are useful when you want to include more complex content such as a block of HTML with merge fields, quotes and links.

Examples

Create a variable called count, and assign it a value of 1:

Create a variable called intro and assign it some text, including a merge field:

This example includes a switch to swap out a store's name and contact phone number in an email depending on where each contact lives. If the contact doesn't match one of the other cases it will fall back to the Auckland store details. The name and phone number can be merged anywhere throughout the email so long as they're between the Variable and EndVariable tags.


Increment/decrement a variable

If your variable is a WholeNumber type, then you can increment or decrement that number.

This is often used to keep count of something, such as how many rows you have in a table.

The amount is optional, if you don't specify this then your variable will be incremented by 1.

Example

This example creates a variable called Count and assigns it to 1, then increments it by 2. The resulting output on the page would be "1, 3":

Last updated

Was this helpful?