Appearance
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
TextRecordis emitted onOutput. - Template context: every property of the input is available by name at the top level (
{{Name}},{{Address.City}}). The whole input is also available asdata,inputDataandinput({{input.Name}}), the flow metadata asmetaData- 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
Templatean emptyValueis 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
3totext/xml, but the dropdown only offers1and2. - The alias
metais not available (onlymetaData).
Example
json
{ "Template": "Hello {{FirstName}},\nyour order {{OrderNo}} contains:\n{{#each Items}}- {{Quantity}} x {{Name}}\n{{/each}}", "FormatType": "1" }Database reader → Handlebars → Mail client