---
id: text--handlebars
title: "Handlebars"
summary: "Renders a Handlebars (Mustache-style) template with the input data and emits the result as a text record. Use it to build e-mail bodies, messages, XML or JSON payloads from flow data."
audience: user
keywords: "input, output, template, formattype"
---
# Handlebars

Renders a Handlebars (Mustache-style) template with the input data and emits the result as a text record. Use it to build e-mail bodies, messages, XML or JSON payloads from flow data.

## Pins

| Pin | Kind | Types | Description |
|---|---|---|---|
| Input | input | any | The data used as template context. |
| Output | output | `Viaducta.Plugins.TextPlugin.Types.TextRecord` | The rendered text in `Value`, the content type in `ContentType`. |

`TextRecord` has three string properties: `Name` (optional resource name, not set by this plugin), `Value` (the text) and `ContentType`.

## Configuration

| Field | Type | Default | Description |
|---|---|---|---|
| `Template` | Handlebars template (code editor) | empty | The template text. |
| `FormatType` | dropdown: `1` TEXT, `2` JSON (required) | `1` | Only sets the output `ContentType`: `1` = `text/plain`, `2` = `application/json`. |

## Behaviour

- For every input one `TextRecord` is emitted on `Output`.
- Template context: every property of the input is available by name at the top level (`{{Name}}`, `{{Address.City}}`). The whole input is also available as `data`, `inputData` and `input` (`{{input.Name}}`), the flow metadata as `metaData` - unless the input has a property with the same name.
- Handlebars syntax: `{{Property}}` (HTML-escaped), `{{{Property}}}` (raw, not escaped), `{{#if Active}}...{{else}}...{{/if}}`, `{{#each Items}}{{Name}}{{/each}}` (`{{this}}`, `{{@index}}` inside loops), `{{#with Address}}{{City}}{{/with}}`, `{{!-- comment --}}`.
- The template is compiled on the first message and reused.
- With an empty `Template` an empty `Value` is emitted and the component shows a warning indicator.

## Notes

- `{{ }}` HTML-escapes the value (`"` becomes `&quot;`, `&` becomes `&amp;`, ...). For JSON or XML output use `{{{ }}}` for values, and make sure the values themselves are valid in the target format (quotes in strings are not JSON-escaped).
- `FormatType` = `2` (JSON) does not validate the output; it only sets the content type.
- The code also maps a value `3` to `text/xml`, but the dropdown only offers `1` and `2`.
- The alias `meta` is not available (only `metaData`).

## Example

```json
{ "Template": "Hello {{FirstName}},\nyour order {{OrderNo}} contains:\n{{#each Items}}- {{Quantity}} x {{Name}}\n{{/each}}", "FormatType": "1" }
```

Database reader → **Handlebars** → Mail client
