Skip to content

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 ​

PinKindTypesDescription
InputinputanyThe data used as template context.
OutputoutputViaducta.Plugins.TextPlugin.Types.TextRecordThe 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 ​

FieldTypeDefaultDescription
TemplateHandlebars template (code editor)emptyThe template text.
FormatTypedropdown: 1 TEXT, 2 JSON (required)1Only 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 ", & becomes &, ...). 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

Viaducta documentation