2022.2

Table Of Contents
isn’tcorrect,thesnippetwillnotappearinthetemplate.
l
ForaJSONsnippet:loadjson(‘snippets/nameofthesnippet.json’).
l
ForaHandlebarssnippet:see"HandlebarsinOLConnect"onpage327.
Tip: Toinsertthecodetoloadasnippetevenquicker,youcan:
l
Drag a snippet into the Script window.Thefunctionthatloadsthescript-loadhtml()
orloadjson(),dependingonthefiletype-willautomaticallybeadded,includingthefile
name.
l
Right-click a snippetandselectCopy Resource Locationtocopytherelativepathof
thesnippettotheclipboard.Itmaythenbepastedintoascript.
Remote snippetsareretrievedinthesameway,exceptthatthefileextensionshouldbe.rhtml
insteadof.html.IfitisaremoteJSONsnippet,thefileextensionis.rjson.
Again,notethatthenameofthesnippetmustbeexactlythesameasintheSnippetsfolder.
Formoreexamples,see"loadhtml()"onpage726and"loadjson()"onpage729.
LoadingpartofanHTMLsnippet
Whenasnippetcontainsapartthatcanbeidentifiedbyaselector,thatselectorcanbeusedtoload
thatpartofthesnippetintoatemplate.
Inscript,usethefollowingcode:
results.loadhtml(‘snippets/nameofthesnippet.html’, ‘selector’)
See"loadhtml()"onpage726formoreinformationaboutthisfunction.
Loadingasnippet,dependingonthevalueofadatafield
Toloadasnippetdependingonthevalueofadatafield,youhavetoaddaconditiontothescript.
Example: ThefollowingscriptevaluatesifthevalueoftheLANGUAGEfieldintherecordis‘En’.
Ifso,thesnippetisaddedtothecontent.
if (record.fields.LANGUAGE == ‘En’) {
results.loadhtml(‘snippets/nameofthesnippet.html’);
}
Anotherexampleisgiveninahow-to;seeLoadasnippetbasedonadatafieldvalue.
Page 391