2022.2

Table Of Contents
var json_data = loadjson("snippets/snippet.json");
results.html(json_data.field1);
Seealso:"Writingyourownscripts"onpage368and"loadjson()"onpage729.
ForanexampleinwhichJSONsnippetsarebeingusedtolocalizeatemplate,seethishow-to:Local-
izingtemplatesusingjson.
Handlebars templates
InOLConnect,Handlebarstemplatesareaspecialkindofsnippets.Justlikeothertypesofsnippets
(see"Snippets"onpage250),HandlebarstemplatesarestoredintheSnippetsfolderonthe
Resourcespane,buttheirfilenameendsin.hbs.
HandlebarsisthenameofaJavaScriptlibrarythatimplementsatemplatinglanguage(see
https://handlebarsjs.com/).Itusesatemplateandaninputobjecttogenerateoutput.
ThetemplatelookslikeregulartextwithembeddedHandlebarsexpressions.Ahandlebarsexpression
issomecontentsenclosedbydoublecurlybraces:{{...}}.Forexample:
<p>Hello {{firstname}}!</p>
Whenthetemplateisrendered,theseexpressionsarereplacedwithvaluesfromaninputobject.
TheHandlebarslibraryisintegratedinOLConnectDesigner.ThismeansthatyoucanuseHandle-
barsexpressionsinallsections(asofversion2022.2),aswellasinaspecialtypeofsnippetscalled
"Handlebarstemplates"(asofversion2022.1).
ThebigadvantageofusingHandlebarssnippetsinOLConnectisthatonlyoneortwoverysimple
Designerscriptsareneededtoreplaceapotentiallylargenumberofexpressionswithvaluesandinsert
thecontentinasection.ThisisespeciallybeneficialforOLConnecttemplateswithmanysnippetsand
variabledatathatwouldotherwiserequirealargenumberofscripts.
WorkingwithHandlebarstemplatesinvolvesalittlebitofscripting.Ifyouarenewtoscriptinginthe
Designer,firstread:"Writingyourownscripts"onpage368.
Note: TheinformationinthisOnlineHelpfocusesontheimplementationofHandlebarsinOL
Connect.ForgeneralinformationaboutHandlebarsandhowtouseit,seethefollowingweb
sites:https://handlebarsjs.com/andhttps://devdocs.io/handlebars.
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.
Page 255