Skip to main content
Handlebars

Using Handlebars in Synatic

Martin Naude avatar
Written by Martin Naude
Updated over 3 years ago

Handlebars is a text templating language that can be used to perform complex operations and return string output. Its main use is in HTML and Document generation, but Synatic uses it as a parameterization language and can generally be used in most places that have text input.

More details can be found at: https://handlebarsjs.com/

Handlebars Syntax

Handlebars is interpreted between any two curly braces: {{}}. Any items between the braces are interpreted as Handlebars and executed.

Paths

To access the current record, parameter information or specific run information, do notation is used. Dot notation navigates an object through a series of "dots". E.g.
If you had the object tree:

The following would apply using dot notation:

  • {{record.field1}} = "a"

  • {{record.field2.subField1}} = 1

  • {{record.field2.arrField.1}} = "af2"

To get the the value in Handlebars you'd use:

  • {{record.field1}}

Functions

Handlebars provides functions with the format:

  • {{<functionName> <p1> <p2>}}

For example, the padLeft function, which pads a value with the specified string to the specified length:

  • {{padLeft record.field 1 3 'x'}} would result in xxa

Synatic has a large collection of Handlebars functions.

Loops

Handlebars can loop through an array of data and output a value for each element:

{{#each}}
expression...
{{/each}}

For example:

{{#each record.record.field2.arrField}}
Value: {{this}}
{{/each}}

Would result in:
​Value: af1
​Value: af2
​Value: af3

The "this" keyword refers to the current element being processed in the each block

Detailed Help

You can get more detail on Handlebars by visiting their site at https://handlebarsjs.com/

Did this answer your question?