2022.2

Table Of Contents
"file:///C:\\Users\\Administrator\\Desktop\\Handlebars_LoadFile.hbs"
orforwardslashes:
"file:///C:/Users/Administrator/Desktop/Handlebars_LoadFile.hbs"
l
Thedatacanbethecurrentrecordorpartofit,oraJavaScriptobject(whichmayinclude
therecordorpartofit-see"HandlebarsAPI"onpage344foranexample).
Ifnodataispassed,thecurrent recordwillbeused.
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.
Page 341