2022.1

Table Of Contents
See also: "Handlebars API" on page460.
Using Handlebars templates: examples
Rendering a Handlebars template repeatedly
A Handlebars template is dynamic by nature. It is converted (compiled) to a JavaScript function.
The Designer script that calls that function must pass data to it, and the result of the function will
depend on that data. If the script calls that same function repeatedly, each time with different
data - for example from a detail table -, the result of each call will be a different piece of HTML.
For example, this script loops over a detail table, each time passing different data to the same
(compiled) Handlebars template.
let policies = record.tables.Policies;
let html = '';
for( var i = 0; i < policies.length; i++) {
{html += Handlebars.render( 'snippets/policy.hbs', policies[i] );
}
results.replaceWith( html );
Selecting a Handlebars template based on a data field
An approach that is also used with HTML snippets is to use the value of a data field in the
current record to determine the name of the Handlebars template to use.
This is an example:
let html = ''
let policydata = record.tables.Policy
for (var i=0; i < policydata.length; i++) {
let templateName = 'snippets/' + policydata[i].fields
['snippetName'] + '.hbs'
html += Handlebars.render( templateName, policydata[i] )
}
results.replaceWith( html );
Styling and formatting
In the Designer you have everything at hand to make your templates look good: colors, fonts
and all the tools to position, align and embellish elements in your designs. This topic informs
Page 290