2022.2

Table Of Contents
4. Double-clickthenewfiletoopenitintheDesignerandfillitwithHTMLtextandHandlebars
expressions.
TheeditorforHandlebarssnippetsdoesnothaveaDesignview.HTMLwithHandlebarsexpressionsis
notnecessarilyvalidHTML.ProcessingitwithanHTMLparsermightbreakboththeHandlebars
expressionsandtheHTML.
Moreaboutexpressionsandthefunctionsthatyoucanuseinexpressionscanbefoundinthetopics
"Handlebarsexpressions"onpage328and"Usingfunctionsinexpressions:Helpers"onpage330.
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385.)
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"onpage344foranexample).
Ifnodataispassed,thecurrent recordwillbeused.
Page 256