2022.2

Table Of Contents
CreatingaHandlebarstemplate
Tocreateanew,emptyHandlebarstemplate:
1. OntheResourcespane,right-clicktheSnippetsfolderandselectNew Snippet.
2. Selectthetypeofsnippetthatyouwanttocreate:Handlebars template.
3. Givethesnippetaname.
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:
Page 340