> For the complete documentation index, see [llms.txt](https://doc.dastra.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.dastra.eu/en/features/general/email-templates.md).

# Email templates

Learn how to write message templates with dynamic fields, conditions and loops to communicate with your customers or colleagues.

## General

Message templates are available in data subject requests, tasks, questionnaire invitations, invitations to complete a processing activity or a data breach, and workflow rules that send a message. Once saved, they are a quick way to communicate with stakeholders. The data of the object concerned can be inserted in the text, with conditions and loops to retrieve more information.

This page explains how to write a template. For template types, sharing, import and export, see the [Message templates](https://doc.dastra.eu/en/features/settings/message-templates.md) page.

## How to use

To use a template, click **Select a template** next to the message writing area.

<figure><img src="https://2697025545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvBxs22wUMicv9uWp6C-1972196547%2Fuploads%2Fgit-blob-d21660a7a29de8d069dbb4fe11c2dc67202cc698%2Fgeneral-email-templates-1.png?alt=media" alt="Writing area of a data subject request message with the Select a template button"><figcaption><p>The Select a template button in a data subject request</p></figcaption></figure>

The **Select a template** panel opens. Search the list for a template, open the **Shared templates** or **Own templates** of each type, or choose another workspace that you have access to. Click **Select** next to the template you want.

<figure><img src="https://2697025545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvBxs22wUMicv9uWp6C-1972196547%2Fuploads%2Fgit-blob-7d72a293c7531ea2a7eedd99bc7eb50b8075bb89%2Fgeneral-email-templates-2.png?alt=media" alt="Select a template panel with the search, the tabs by type and the New template button"><figcaption><p>The panel to select a template</p></figcaption></figure>

If no template fits, click **New template**. The creation window includes:

* the **Name** of the template, so that you can find it later;
* the **Template body**, the input area;
* the option to share the template with all the users of the workspace;
* the **Preview** tab, which displays the rendering of the message in real time;
* the **Input Data** tab, which displays the data of the object concerned by the template.

The **Preview** and **Input Data** tabs only appear if you create the template from the place where you write the message, not from the settings.

<figure><img src="https://2697025545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvBxs22wUMicv9uWp6C-1972196547%2Fuploads%2Fgit-blob-d94ccf96af487bd4d14622468c1a4256ede3b434%2Fgeneral-email-templates-3.png?alt=media" alt="Template creation window with the name, the template body, the preview and the Input Data tab"><figcaption><p>The template creation window</p></figcaption></figure>

## Customize the template

In the template body, you can apply styles and insert images or tables. The result appears in the **Preview** tab.

To insert a piece of data from the object, click the braces icon of the toolbar (**Insert dynamic fields**) and choose a field in the list. The value of the field is inserted at the cursor.

<figure><img src="https://2697025545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvBxs22wUMicv9uWp6C-1972196547%2Fuploads%2Fgit-blob-bf854acee7ee8ed340d3ca0acfb1b139bc227a0d%2Fgeneral-email-templates-4.png?alt=media" alt="List of dynamic fields opened from the toolbar of the template editor"><figcaption><p>Inserting a dynamic field</p></figcaption></figure>

## Dynamic fields

Fields surrounded by double braces are variables: they are replaced by the values of the corresponding object (here a data subject request).

### Use a field from the Input Data

The **Input Data** tab lists the properties of the linked object. To display the message of the request, for example:

1. Find the field in the **Input Data** tab.
2. Enter its name in the template body with the syntax `{{message}}`.
3. Check the result in the **Preview** tab.

You can go further with loops, conditions and date formats.

### Conditions

A conditional block is only displayed under certain conditions. It starts with an `if` tag and ends with an `endif` tag. For example:

```liquid
{% if attachments != blank %}
  You have an attachment
{% endif %}
```

The block is only displayed if the request contains an attachment.

### Loops

Loops work in the same way, with a variable internal to the loop:

```liquid
{% for purpose in purposes %}
  {{ purpose }}
{% endfor %}
```

In this example, the loop goes through the `purposes` list and displays each item in the `purpose` variable.

### Date format

The dates of the Input Data are not presentable as they are. Apply a format to them:

```liquid
{{ dateCreation | date: "%d-%m-%Y at %H:%M" }}
```

This template gives, for example, 15-03-2023 at 15:40.

### A more complete example

The body text below uses all the elements above:

```liquid
Hello,

We have received your data subject request on {{ dateCreation | date: "%d-%m-%Y at %H:%M" }} concerning {{ givenName }} {{ familyName }}.

The request relates to the following purposes:
{% for purpose in purposes %}
* {{ purpose }}
{% endfor %}

{% if attachments != blank %}
We have received the following attachments:
{% for attachment in attachments %}
* {{ attachment.fileName }}
{% endfor %}
{% endif %}

We will keep you informed of the progress of your request.

Kind regards,
{{ operator.displayName }}
```

For the request currently being processed, the message is transformed as follows:

<figure><img src="https://2697025545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvBxs22wUMicv9uWp6C-1972196547%2Fuploads%2Fgit-blob-3f7890cc58fc2cb07d9bfdcacba4803a29c1f1c0%2Fgeneral-email-templates-5.png?alt=media" alt="Preview of the message generated from the complete template for a data subject request"><figcaption><p>The rendering of a complete template</p></figcaption></figure>

## Going further

Templates use the Liquid syntax. See the [Liquid documentation](https://shopify.github.io/liquid/) for the list of tags and filters.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.dastra.eu/en/features/general/email-templates.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
