In Dialogue you can use the scripting language Freemarker to manipulate content and include the various available merge variables. You can find the full list of Freemarker built-ins here for reference. In this article we share some useful code examples to use in your content.
Contact fields and properties
There are many different merge variables available in Dialogue to use in sms and email content: contact fields, mail job fields, newsletter and article fields, placeholders for online view and webform links, and custom and pre-defined properties of various objects. You can find more details on where and how to use these on our support portal (login needed).
It’s often useful to assign variables to use elsewhere in your template or in Freemarker code. Variables can be assigned in the following ways:
Default value for merge fields
If a merge variable doesn’t always have a value, it’s necessary to prevent a publication error by providing a fallback, either by using ! followed by the default value (or an empty string, or simply nothing), or by using the has_content operator in an if-statement.
Conditional statements: if, switch and hashes
Freemarker can be used to display content based on merge fields or other available variables. Apart from if-statements you could consider a switch statement when a condition has multiple values and each has a different outcome. A similar result can be reached by creating a hash with a key-value pair.
Date and time values
The variables .now and currentdate.datetime each return the current date-time and can be converted to a date or a time value. You will often want to assign this value for further operations, like using one of the various Freemarker built-in operators for dates and times to convert the value to text. You can use a locale setting to regionalize the output of the built-ins (make sure to use <#noparse>for the locale if it involves contact date fields in a newsletter). For more details check out this article on our support portal (login needed).
In Dialogue you can use the following 2 custom date functions: addDays to add a number of days to a date value and substractDates to find the difference between 2 dates.
Online view link
There are several ways to include the online view link in emails. The easiest one is the placeholder (see the first snippet), but for a stylable link you can use one of other options. If you use these in a newsletter you need to use <#noparse> because the links contain the contactId.
Importing external data
Various useful Freemarker snippets
You can find more information on the ?then operator here.