2022.2

Table Of Contents
UsingaHandlebarstemplateinasection
AlthoughHandlebarstemplatescontainHTMLtext,theycannotbeinsertedintothecontentofasec-
tionastheyare.Theexpressionswouldnotbereplacedwithdata.
WhatittakesisashortscriptthatreplacestheHandlebarsexpressionswithvaluesandthenaddsthe
contentoftheHandlebarstemplatetoasection.
1. OntheScriptspane,clickontheblacktrianglenexttotheNewbuttonandselectStandard
Script.
2. Givethescriptaname.
3. Entertheselectorthatwillidentifyelementsinthetemplateforwhichthescriptshouldrun.(See:
"SelectorsinOLConnect"onpage825.)
4. WritealineofcodethatcallsthefunctionHandlebars.render(template, data).
l
Thetemplatecanbe:
a. thenameofaHandlebarstemplate(.hbs)inthetemplate
b. thenameofaHandlebarstemplate(.hbs)ondisk(file:///)
c. thenameofaremoteHandlebarstemplate(.hbs)(http://orhttps://)
d. astringthatcontainsHTMLandHandlebarsexpressions.
Withasnippetondisk,thecompletesyntaxis:file://<host>/<path>.Ifthehost
is"localhost",itcanbeomitted,resultinginfile:///<path>-notethethreeforwardslashes
afterfile:.
Intheremainderofthepathyoucaneitheruseescapedbackwardslashes:
"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"onpage780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 )
Page 667