Template engine
What is template engine
The template engine allows you to customize the text of messages (e-mail, SMS, push) in mass mailings and campaigns. Each customer will see the information in the message that is relevant to him.
The template engine includes:
Variables – data about the customer, his receipts and products in the receipt. For example, with the help of a variable you can display the customer's name in the message text;
Macros - functions that allow you to display information about promo codes, surveys, etc;
Control structures - cycles, conditions, filters.
An example of using a variable in the text of a message:
When you send a message, the variable will be replaced with a value, for example:
Variables in the Platform
Variables allow you to substitute data in the text of the message (and for emails - in the subject of the email)
From customer’s profile:
Customer’s attributes and metrics;
Links to manage subscription;
Attributes and content from last receipt;
Dates;
And any other attribute;
About customer’s receipts;
About products included in a receipt;
About product category.
Variables can be of the following types:
Read here in more detail about the fields.
Variable entry format: {{variable_name}}
.
System variables
The following system variables are available in the Platform:
Variable | Assignment |
{{client.properties.full_name}} | Customer’s full name |
{{client.properties.last_name}} | Customer’s last name |
{{client.properties.first_name}} | Customer’s first name |
{{client.properties.middle_name}} | Customer’s middle name |
{{client.properties.register_date}} | Customer’s registration date |
{{client.properties.city}} | Customer’s city |
{{client.properties.zip}} | Customer’s zip code |
{{client.properties.email}} | Customer’s e-mail |
{{client.properties.password}} | Customer’s password |
{{client.properties.phone}} | Customer’s phone number |
{{client.properties.order_cnt}} | Quantity of customer’s receipts |
{{client.properties.order_sum}} | Total amount of all customer’s receipts |
{{client.orders.first.date}} | Date of customer’s first receipt |
{{client.orders.last.date}} | Date of customer’s last receipt |
{{client.orders.last.number}} | Amount of customer’s last receipt |
{{client.properties.rating}} | Customer’s rating |
{{client.links.profile}} | Link to customer’s profile in the Platform |
{{client.links.unsubscribe}} | Link to subscriptions management |
{{client.links.web_version}} | Link to web version of e-mail |
{{client.properties.bonus_active}} | Quantity of active bonuses |
{{client.properties.bonus_expect_activate}} | Quantity of bonuses awaiting activation |
{{client.properties.bonus_expect_deactivate}} | Quantity of bonuses awaiting deactivation |
{{client.properties.bonus_expect_deactivate_date}} | Bonuses deactivation date |
{{client.properties.bonus_expect_deactivate_next}} | Bonuses expected to be deactivated in the nearest time |
{{client.eventContext.<field_code>}} | Data from context of event |
{{client.containers.lost_cart.items}} | Abandoned cart contents |
User variables
User fields Customer/Receipt/Receipt lines/Product category are accessed via their codes using the construction of the following form {{client.properties.<field_code>}}
. Example:
You can find out the field code in Settings->Fields field in the Customer’s/Transactions/Transactions lines/Categories tab.
For example, code of receipt "Type of payment" attribute – "payment_type".
Use the following format to form variable:
{{client.properties.<field code>}} – attribute value in customer’s profile;
{{client.orders.first.<field code>}} – attribute value in customer’s first receipt;
{{client.orders.last.<field code>}} – attribute value in customer’s last receipt.
To output the attribute values of products in the abandoned cart, first and last receipt, product category, you should use cycles.
Default value
For string type attributes you can set a default value. If attribute is not specified this value will be displayed in the text of the message.
For example, the message should address your customer by name, and if name is unknown, the message should display default value:
Macros
Macros are comparable to functions in programming languages.
For example {{client.promocode('promo code group')}}
macros finds and returns a promo code from a group.
System macros
The following macros are available in Platform:
Macro | Purpose |
{{"now"|date('format')}} | Current date |
{{client.promocode('promo code group')}} | Issue to the customer a promo code from a group of promo codes |
{{client.last_promocode('promo code group')}} | Last promo code issued to the customer from the group |
{{client.last_campaign_promocode('promo code group')}} | Last promo code from the group, issued to the customer as part of this campaign |
{{client.template_constant('name')}} | Region constant |
{{client.poll('name_of_poll')}} | Link to the poll |
Dates format
Fields with the date type can be displayed in different formats. You can use any combination of the following values to represent the format:
Year:
y – 2 digits (for example, 97, 20);
Y – 4 digits (for example, 1997, 2020);
m – month (in format from 01 to 12);
d – day (in format from 01 to 31);
h – hour;
i – minute;
s – second.
Example 1. Displaying date in a message
For example, if specified format is 'Y-m-d' , the date will be displayed as '2020-10-20'. If the format is 'd.m.Y h:i', it will be displayed as '20.10.2020 11:56'.
Example of using the macro: thanking customer for the last order.
The customer will receive a message with a line like this:
Thank you for the order from 29.06.2020!
Example 2. The displayed date is several days older than the current date
In order to display the date several days older than the current date, use this macros:
Tomorrow's date will be displayed in the message.
Example 3. Date output - one month after the customer registration date
Example: output date +1 month from the customer registration date.
Inserting a variable or macros into a message
To insert a user variable, you should type it manually.
Preview
You can preview the message for a particular customer. To do this, enter the customer's Last name/First name/Phone number/E-mail/Identifier (local_id) in the Customer field. For the search results to be precise, it is recommended to search the customer by phone number/e-mail/customer local identifier.
The search in the Customer field is case-sensitive. The client's first and last name must be capitalized.
Control structures
You can use control structures to create more complex patterns based on variables and macros. Control structures include for-cycles, conditions (if/elseif/else) and filters. Control structures are entered inside blocks {% ... %}.
Variables
To use the same expression multiple times in a message, you can enter a variable.
For example, let's enter a variable lost_cart for the array of elements in the abandoned shopping cart:
Cycles
In the following cases it is necessary to use cycles:
Output of product attributes in the customer's first/last receipt;
Output of product attributes in the abandoned cart;
Output of product category attributes.
For example, you can output the names of all products in the customer's last receipt:
Output the name and color for all products in the abandoned cart:
Output the category name for all products in the last order:
Conditions
You can output only those data in the message for which the specified condition is met.
For example, you can give out a promo code only to customers from Berlin:
Here are a few variants of conditions:
{% If client.properties.city == 'Berlin' %} – if the customer is from Berlin;
{% If client.properties.city %} – if the customer specified a city;
{% If not client.properties.city %} – if the customer did not specify a city;
{% If client.properties.city == 'Berlin' OR client.properties.city == 'Munich' %} – if the customer is from Berlin or Munich;
{% If client.properties.city == 'Berlin' AND client.properties.first_name == 'Klaus' %} – if the customer is from Berlin and his name is Klaus
Filters
Filters are available for arrays:
sortArray – allows you to sort an array by attributes values:
sortArray('date', true) – sort by date in descending order;
sortArray('date', false) – sorting by date in ascending order (elements can be sorted not only by date, but also by other attributes);
get – outputs the specified number of elements:
get(10) – outputs the first 10 elements of the array;
date_diff('date') – outputs the number of days between two dates. For example, you can output how many days have passed from 2020-11-11 to the current date:
Output information from abandoned cart
Example of using filters: output name, image and price for 10 products that were added to the cart first, from the abandoned cart.
To make the product name a link, use the tag with the href attribute:
Last updated