2022.2

Table Of Contents
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780.
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] );
}
results.replaceWith( html );
Selecting a Handlebars template based on a data field
AnapproachthatisalsousedwithHTMLsnippetsistousethevalueofadatafieldinthecurrent
recordtodeterminethenameoftheHandlebarstemplatetouse.
Thisisanexample:
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 );
Partials
PartialsarenormalHandlebarstemplatesthatmaybecalleddirectlybyothertemplates.Thistopic
explainshowtoworkwithHandlebarspartialsinOLConnect.
InformationaboutHandlebarstemplates(snippets)inOLConnectcanbefoundinthetopics"Handle-
barstemplates"onpage774.
Page 777