Template Service
Use the template service to build templates that can be used to generate HTML-formatted mails and PDF documents.
Basic functionality
Define templates
The following JSON example shows how you can define a template:
The schema
key allows you to define the variables that must be provided to render a template.
The fields
key allows you to define the different outputs that the template service should render. You can reference input fields and other fields by using $content.<variable>
Under the hood, this service uses Apache Velocity as a template engine. Take a look at the Velocity User Guide for in-depth information how to write more complex templates.
Create or update templates
The CLI has built-in tooling to make working with the template service a lot easier. Using the CLI you can easily upload full HTML files as template fields as well as define templates that extend other templates.
Create a new folder and add a template.json
file. This file has the same structure as the example template definition file mentioned higher on this page.
Additionally, you can add <field_name>.html
files in the same folder. The CLI will include these html
files as a field in the JSON before uploading.
To create and synchronise your template, execute the following command:
Visit the CLI documentation for more details on how to manage templates using the CLI.
Render templates
Rendering a template results in a json
that is returned with all variables filled in. For this we need to supply the template service with the variables defined in the schema
defined in the template definition.
Using the example template from the previous section, we have to provide the following input:
With the above input the template service will return the following output:
Our template is now resolved into a message that makes sense.
E-mail templates
Templates that are defined in the template service can be easily used together with the mail service to create formatted mails.
To define e-mail templates there are additional requirements on the fields
that must be present:
body
- the content of this field will be used as the body for the e-mailsubject
- the content of this field will be used as e-mail subject
For more info how to send e-mails using templates, take a look in the mail service documentation
Last updated