2022.1

Table Of Contents
Using a Handlebars template in a section
Although Handlebars templates contain HTML text, they cannot be inserted into the content of a
section directly. The following steps need to be taken in order to replace Handlebars
expressions with values and then add the content of a Handlebars template to a section.
Render the Handlebars template
First the template needs to be rendered, i.e. converted into HTML, replacing the expressions
with values. This can be done with one line of code in a standard Designer script. Create a
standard script and call the function:
Handlebars.render(template, data).
For example:
var html = Handlebars.render( "snippets/policy-info.hbs", record );
The template can be:
l the name of a Handlebars template (.hbs) in the template
l the name of a Handlebars template (.hbs) on disk (file:///)
l the name of a remote Handlebars template (.hbs) (http:// or https://)
l a string that contains HTML and Handlebars expressions.
With a snippet on disk, the complete syntax is:file://<host>/<path>. If the host is"localhost", it
can be omitted, resulting infile:///<path> - note the three forward slashes after file:.
In the remainder of the path you can either use escaped backward slashes:
"file:///C:\\Users\\Administrator\\Desktop\\Handlebars_LoadFile.hbs"
or forward slashes:
"file:///C:/Users/Administrator/Desktop/Handlebars_LoadFile.hbs"
The data can be the current record or part of it, or a JavaScript object.
If no data is passed, the current record will be used.
Add the HTML to a section
Finally, the rendered HTML can be added to the content of a section.
For example: results.replaceWith( html )
Alternative: compile and call the template
The render() function actually does two things:
Page 783