Email templates are prepared email messages, containing subject, HTML and text content, with variables, placeholders and template code that will be processed and replaced when an email is sent.
Locale = Language
During template processing the used Locale becomes important. It is used for example when choosing a translation, or how a date or time representation is generated.
A locale can consist of several parts, but the most important is Language. It can also contain a Country. These parts are often shown like this: en
or en_US
. The first locale contains only a language (English) while the second locale specifies also a country (American English). If you need to customise the translations for different regions, you can do that by adding the country to the locale.
If you add Locale specific properties, you should also specify a default Locale in your template. It is used if no other locale is selected when the email is being processed.
Template engines
Templates can be written as-is, but likely you will want to add dynamic content. Dynamic content may be parameters in links, the recipient’s name, or even the whole content using translations. How these dynamic parts are defined depends on the selected template engine.
You can use templates in the subject, HTML and text content. They will all be processed identically. It is up to you to make sure the templates are valid and produce valid output.
Apache Velocity
TIS supports templates written for Apache Velocity 2.2. The Generic Tools 3.0 package is included with standard tool names.
You can reference properties using the $
prefix followed by the property name. If the property has sub-properties, you can chain the names together separated by .
period characters.
For this reason you cannot have period characters in property names.
Example:
Hi ${recipientUser.firstName} ! The time and date is currently ${date.systemDate}. Your email is $recipientEmailAddress. // After processing, the above is converted to: Hi Sue ! The time and date is currently Fri Mar 13 14:42:23 EET 2020. You email is sue@example.com
There are many options and tools you can use to create dynamic content. Check the links below for more information.
Variables in translations
With Velocity you can have property references and dynamic content in properties, including locale properties (the translations). You can use $render.eval()
method to “evaluate” these parts in properties before they are displayed.
Example:
Properties | firstname=Sue subject=Mitä kuuluu ${firstname}? |
---|---|
Template | <h1> $render.eval($subject) </h1> |
Output | <h1> Mitä kuuluu Sue? </h1> |