2022.2

Table Of Contents
Example:
var html = Handlebars.render( "snippets/policy-info.hbs", record
);
5. WritealineofcodethataddstherenderedHTMLtothecontentofthesection.
Example: results.replaceWith( html )
6. Savethescript.Makesurethatthereisatleastoneelementinthesectionthatmatchesthe
selectorofthescript.
Alternative: compile and call the template
Therender()functionactuallydoestwothings:
1. Compile the Handlebars template into a function
WhenaHandlebarstemplateiscompiled,itisactuallycompiledintoaJavaScriptfunction.
2. Call the function to replace expressions with data
Thesecondstepistocalltheresultingfunction,passinginsomedata.Thefunctionwillreplace
theexpressionswithvaluesfromthedataandwillthenreturnHTML.
InsteadofcallingHandlebars.render()youcouldcallHandlebars.compile()andthencallthe
resultingfunction.
Example: var myFunction = Handlebars.compile( "snippets/policy-
info.hbs", record);
let html = myFunction( record );
results.replaceWith( html )
HandlebarssamplecodefromanonlinesourcewillusethetwoseparatestepssinceHandle-
bars.render()isonlyavailableinOLConnect.
Seealso:"HandlebarsAPI"onpage344.
UsingHandlebarstemplates:examples
Rendering a Handlebars template repeatedly
Thisscriptloopsoveradetailtable,eachtimepassingdifferentdatatothesame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] );
Page 257