Whenever Zenario sends an email, a template is used. Templates may be any kind of automated message which may contain text, links, images or user details. Some examples are form submission confirmations, password reset messages, consent requests or admin notifications.
Templates can be managed in Organizer, in the Email section.
Email templates can be edited using rich text or HTML and Twig code.
Twig is a powerful HTML template engine. It offers all the features already available for the rich text editor, such as merge fields, along with other extras (e.g. conditional logic, loops, escaping strings). Zenario core functions can be used in a Twig template.
Starting with version 8.4, Zenario allows the use of Twig snippets in email templates. Text may be formatted using HTML, and merge fields may be used to retrieve data. This is a sample template written using Twig:
The message will look like this:
Every form input field has a merge name, as well as an optional custom code name (e.g. "message" instead of the default "unlinked_textarea_1"). These can be found on the left-hand side panel when editing a form:
To use a merge field in an email template, put double braces around the code name {{like this}}. Starting with version 8.4, the default merge name and a custom code name (if assigned) can be used interchangeably.
A dropdown of all possible merge fields is available above the "Email body" text area.
To execute a Twig statement, put it inside a delimiter: {% ... %}. One example of supported statements is an "if" statement.
Twig framework supports if / elseif / else statements. The syntax is described below.
Any number of other conditions may be added using {% elseif %} and {% else %} statements. These statements are optional, but the final {% endif %} statement is mandatory.
Operators such as and, or, not, >, <, >=, <=, ==, != may be used for more control.
Example
The template below is written so that the user will be greeted:
- using their full name if both the first and last name were entered,
- or using their first name only if the last name was not entered.
Results
First name only:
First and last name:
If a string contains characters that might affect the resulting HTML (e.g. an apostrophe), it can be piped through the escape filter |e to render these characters harmless.
By default, only HTML is escaped, but certain parameters may be used to escape, for example, Javascript ('js'), CSS ('css') or a URL ('url') if needed.
To find out more about Twig, visit the project homepage.