2022.1

Table Of Contents
1. Compile the Handlebars template into a function
Handlebars templates need to be compiled first. When a Handlebars template is
compiled, it is actually compiled into a JavaScript function.
2. Call the function to replace expressions with data
The second step is to call the resulting function, passing in some data. The function will
replace the expressions with values from the data and will then return HTML.
Instead of calling Handlebars.render() you could call Handlebars.compile() and then call the
resulting function. For example:
var myFunction = Handlebars.compile( "snippets/policy-info.hbs",
record);
let html = myFunction( record )
Handlebars sample code from an online source will use the two separate steps since
Handlebars.render() is only available in Connect.
See also: "Handlebars API" on page990.
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.
Page 784