Working with variables in template editor

Jaroslav Bouška Jaroslav Bouška
16. October 2023

Besides replacing base recipient variables, Boldem provides the option for conditionally rendering individual blocks, browsing structures (e.g., items in cart), and formatting outputs. Below, you will find a basic overview of each variable and its usage.

Base variables

VariableDescription
{{ contact.salutation }}In practice, you will likely be using the variable called Vocative for recipient salutations. You can find more information on this in the First name declension chapter.
{{ contact.company }}Recipient’s company
{{ contact.surname }}Recipient’s last name
{{ contact.name }}Recipient’s first name
{{ contact.email }}Recipient’s e-mail
{{ contact.mesto }}Custom field, which we have entered in the system as mesto (city).
{{ unsubscribeUrl }}Unsubscription URL. If the campaign has unsubscribing feature enabled and this variable is not present in the email body, the default unsubscribe text will be automatically included.
{{ webMailUrl }}URL to display email message content on the website.
{{ webMailWithHeaderUrl }}URL to display email message on the website. The email will be displayed on the website including sender and recipient entries.

First name declension in Czech language

Boldem offers automatic declension of first names into the 5th case – vocative. The variable Vocative is used to generate salutations. Use this variable by inserting the following string into the template:

{{ vokativ contact.name }}

After dispatching the message, this string will be replaced with the recipient’s first name in the correct vocative form. For example, if the recipient’s first name is Jana, the template will display Jano. Alternatively, if you want to choose a more familiar approach with Ahoj Jano (Hi Jana), use the following string:

Ahoj {{ vokativ contact.name }},

For example, if your goal is to express gratitude for registering, use the following string:

Thank you for your registration, {{ vokativ contact.name }}!

example of using personalization in Boldem - first names

In the example above, we use data retrieved from the base variable contact.name, specifically, the first name associated with each recipient. Alternatively, you can obtain input data from custom fields or from a JSON file sent when dispatching a transactional email.

Last name declension

Boldem can automatically help you with declension of both first and last names up to the 5th grammatical case. To generate a salutation, use the Vocative function. You can use this function by inserting the following string into the template:

{{ vokativ contact.surname }}

This string will be replaced with the recipient’s last name in the appropriate grammatical case after the message is sent. For example, if the recipient’s last name is Novák, the template will display Nováku. Typically, surname declension is not used alone but combined with gender distinction. See the following section for details.

Declension with gender-based salutation

In a vast number of personalized salutations, not only do you need to correctly spell both the first and last names, but also to change the salutation to match the person’s gender. Since Boldem allows you to enter the gender of recipients, using the designated variable should make this process a walk in the park.

In certain cases, the gender of the recipients is automatically stored according to the first or last name entered (e.g., when manually inserting recipients or optionally during bulk import). In the case of non-standard names, the gender is not automatically set. Therefore, it is advisable to verify those names first and add the names manually if needed.

If you have set the gender of your recipients, you can use the string below in the template instead of manually addressing recipients:

Thank you for your registration {{ if contact.sex != null }}{{ if contact.sex == 1 }}, Mr. {{ end }}{{ if contact.sex == 0 }}, Mrs. {{ end }}{{ vokativ contact.surname }}!{{ else }}!{{ end }}

This string is actually a script code that evaluates whether the recipient has the correct gender setting, thus applying the salutation accordingly:

  • If the gender is set to Male and the recipient’s last name is Novák, the following salutation will be used: Thank you for your registration, Mr. Novák!
  • If the gender is set to Female and the recipient’s last name is Svobodová, the following salutation will be used: Thank you for your registration, Mrs. Svobodová!
  • If gender is not set, the following universal salutation will be used: Thank you for your registration!

Naturally, you can modify the text of the salutation (bold text in the example) to your liking. We recommend that you always test the salutation thoroughly on a small sample of test recipients using every possible variation (i.e. with both genders and a recipient without gender).

example of using personalization in Boldem - last name

In the example above, we use data retrieved from the contact.surname and contact.sex base variables, which represent the last name and gender associated with each recipient. Alternatively, you can obtain input data from custom fields or from a JSON file sent when dispatching a transactional email.

Conditions

Using the keyword if makes it easy to enter each condition:

{{ if product.price == 100 }} Expression is true {{ else }} Statement is null or false! {{ end }}

We can also use a variant with if else:

{{ if product.price > 100 }}
Very expensive
{{ else if  product.price < 100 && product.price > 50 }}
Expensive
{{ else }}
Cheap
{{ end }}

Loops

Loops are used to pass and display individual elements from the data field.

Basic loop for iterating through the product field

{{ for item in products }} This is the product {{ item.title }} {{ end }}

Data fields can be sorted by title

{{ for item in products | array.sort "title” }} This is the product {{ item.title }} {{ end }}

Within the loop, it is possible to retrieve additional data regarding the iterated information

{{ for.index }} – returns the iteration index

{{ for.first }} – returns true if it is the first iteration

{{ for.last }} – returns true if it is the last iteration

{{ for.even }} – returns true if it is an even iteration

{{ for.odd }} – returns true if it is an odd iteration

Práce s datem

{{ date.now }} – vypíše aktuální neformátované datum
{{ date.now | date.to_string "%d.%m.%Y" }} – vypíše aktuální datum ve formátu dd.mm.yyyy
{{ date.now | date.to_string "%d.%m.%Y %H:%M" }} – vypíše aktuální datum a čas ve formátu dd.mm.yyyy hh:mm

date.now je možné nahradit libovolnou proměnnou, která obsahuje datum, například datum vytvoření objednávky nebo košíku

Kompletní seznam možných proměnných naleznete na stránce “Práce s datem”

Output formatting

{{ dateVariables | date.to_string "%d. %m. %Y %H:%M" }} – formátování data a času

{{ 5.4329 | math.round 2 }} – rounding to 2 decimal places

{{ textVariables | string.upcase }} – returns the entered text in upper case

{{ textVariables | string.downcase }} – returns the entered text in lower case

{{ textVariables | string.capitalizewords }} – capitalizes the first character of each word

{{ textVariables | string.base64_encode }} – encodes the text entered into the variable as base64

Generating Data

{{ math.uuid }} – creates a new UUID

{{ math.random 1 100 }} – returns a random number from the range of 1 to 100

{{ date.now }} – returns the current date

{{ date.now.year }} – returns the current year