Liquid Templates in the WebCRM

Liquid-Templates make it possible to personalize emails using the Liquid markup language. In the WebCRM, Liquid-Code can be used in several places:

  • With mailings, Liquid can be used in the body and in the subject field of the mails to be sent.
  • The contents of notification emails as well as some email parameters (e.g. the subject) can be partially or wholly generated using Liquid. An email notification is sent after an activity has been created, after an activity containing an appointment has been modified, and after a comment has been added to an activity.
    This analogously also applies to the contents and some parameters of the emails with which a digest of the comments of an activity is sent. It also applies to password change requests sent via email.
    The email templates for this kind of system messages can be defined in the Templates subsection of the System section.
  • Liquid templates are also used for displaying the items in list views. These templates are part of the respective type configuration.

Liquid basics

Liquid makes it possible to retrieve field values and to process instructions.

Retrieving field values

To retrieve the value of a field, specify its name in double braces. In most cases, names consist of several components separated by a dot. Example:

{{ contact.account.name }}

This causes the value of the name field to be determined. This value replaces the pair of braces and its contents. The name field is part of the account (account) to which the person (contact) for whom the email is sent is assigned.

With mailings, those field values of persons (contact), their account (contact.account), and the mailing concerned (mailing) can be accessed that are also available via the web services API. Furthermore, mailing.event can be used to access the event with which the mailing is associated (if any).

With email templates, activity makes the fields of the activity, plus activity.contact and activity.appointment_contact available. activity.contact refers to the person associated with the activity, activity.appointment_contact refers to the person for whom an appointment was made in the activity.

Instructions (tags)

Liquid offers several instructions for the purpose of conditional evaluation or iteration, for example. Instructions are enclosed in braces marked with a percent character. Example:

{% capture trash %} {% assign contact = activity.contact %} {% comment %} Further instructions {% endcomment %} {% endcapture %} {{ contact.first_name }} {{ contact.last_name }}

The capture instruction serves to assign the literal or generated text to a variable. In the example above, the instruction is only used for formatting the Liquid code without including space characters and line breaks.

By means of an include instruction you can have other templates evaluated in the context of the current template:

{% include "subtemplate" %}

Used in the body of a mailing, this line includes the template named subtemplate. For generating a template name from one or more variable values, use capture:

{% capture subtemplate %}greeting_{{ contact.language }}{% endcapture %} {% include subtemplate %}

These lines include the template whose name is composed of greeting_ plus the language code of the recipient, e.g. greeting_en.