Extra Horizon
GitHub
  • Extra Horizon Documentation
  • Getting Started
    • Start familiarizing yourself
  • Tutorials
    • Medical Device Tutorial
      • Preparation
      • Build your first prototype
        • Define a data model
        • Configure your workflows
          • Workflow 1: Analyze a measurement
          • Workflow 2: Create & store a PDF report
          • Workflow 3: Send an e-mail
        • Define your permissions
          • Update your schema with user permissions
          • Update your schema with group permissions
        • Build the Front-End
          • Set up oAuth in your backend
          • Demo login page
      • Summary & Wrap up
    • Polysomnography (PSG) Tutorial
    • Retool - Building dashboards Tutorial
  • FAQ
    • General
  • Services
    • Identity and Access Management
      • User service
        • Users
        • Groups
        • Global roles
        • Configuration
      • Auth Service
        • Applications
        • OAuth2
        • OAuth1
        • MFA
        • OpenID Connect
          • Google Cloud
          • Azure ADFS
    • Data Management
      • File Service
      • Data Service
        • Schemas
        • Documents
        • FAQ Data Service
    • Automation
      • Task Service
        • Functions
        • Tasks
        • API Functions
        • Examples
          • Hello world (JS)
          • Hello world (Py)
          • Hello world (Docker)
        • FAQ
      • Dispatchers Service
      • Event Service
        • System Events
    • Communication
      • Notification Service
        • Notifications
        • Settings
      • Mail Service
    • Other
      • Localization Service
        • Language Codes
      • Template Service
        • Localizations
      • Payments Service
        • Subscriptions
        • Stripe
        • iOS App Store
      • Configurations Service
  • API Reference
    • OpenAPI Specifications
    • 📦Changelog
      • Per-service Changelog
    • Postman Reference Collection
  • Tools
    • SDK
    • CLI
    • Control Center
  • Additional Resources
    • Resource Query Language (RQL)
    • Handling Errors
    • GitHub
    • API interaction (Python)
    • Migration guide: Enabling verification request limiting
  • ExH Platform
    • 🙋Support
    • ⏱️Usage and Performance
    • 🔓Security
    • 🗺️Regions
    • ⚖️Cloud Subscription Agreement
    • 🇺🇸CFR 21 Part 11
Powered by GitBook
On this page
  • Basic functionality
  • Define templates
  • Render templates
  • E-mail templates

Was this helpful?

  1. Services
  2. Other

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:

example-template-definition.json
{
    "id": "5cff960c46e0fb0007b45cc4",
    "description" : "Example Template Definition
    "schema":
        "type": "object",
        "fields": {
            "firstName": {
                "type": "string"
            }
        }
    },
    "fields": {
        "message": "Hello, $content.firstName"
    }
}

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>

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:

exh templates sync --path ./$TEMPLATE_FOLDER
import { createOAuth2Client } from "@extrahorizon/javascript-sdk";

const exh = createOAuth2Client({
  host: "",
  clientId: "",
});

await exh.auth.authenticate({
  password: "",
  username: "",
});

const schemaDefinition = {
  name: "example-schema",
  description: "This is an example schema",
  schema: {
    type: "object",
    fields: {
      firstName: {
          type: "string"
      }
    }
  },
  fields: {
    message: "Hello, $content.firstName"
  }
}

// Example To Update
await exh.templates.update("<ID>", schemaDefinition);

// Example to Create
await exh.templates.create(schemaDefinition);

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:

{
    "content": {
        "firstName": "John"
    }
}

With the above input the template service will return the following output:

{
    "message": "Hello, John"
}

Our template is now resolved into a message that makes sense.

import { createOAuth2Client } from "@extrahorizon/javascript-sdk";

const exh = createOAuth2Client({
  host: "",
  clientId: "",
});

await exh.auth.authenticate({
  password: "",
  username: "",
});

// Example To Update
const resolvedTemplate = await exh.templates.resolveAsJson("{TEMPLATE_ID}",{
  firstName: "John"
});

Execute the following REST API call to resolve the template:

POST /templates/v1/{templateId}/resolve
{
    "firstName": "John"
}

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-mail

  • subject - the content of this field will be used as e-mail subject

PreviousLanguage CodesNextLocalizations

Last updated 8 months ago

Was this helpful?

Under the hood, this service uses as a template engine. Take a look at the for in-depth information how to write more complex templates.

Visit the for more details on how to manage templates using the CLI.

For more info how to send e-mails using templates, take a look in the

Apache Velocity
Velocity User Guide
CLI documentation
mail service documentation