2022.2

Table Of Contents
Loading a snippet via a script
Itispossible,andoftenveryuseful,toloadasnippetdynamically.
Createascript(see"Writingyourownscripts"onpage808).Inthecodeusethefollowingfunction:
l
ForanHTMLsnippet:loadhtml(‘snippets/nameofthesnippet.html’).
Toinsertthesnippetinthecontentatanypositionwherethescript'sselectorisencountered,
writeresults.loadhtml('snippets/nameofthesnippet.html').
MakesurethatthefilenameisexactlythesameasthefileintheSnippetsfolder.Ifthefilename
isn’tcorrect,thesnippetwillnotappearinthetemplate.
l
ForaJSONsnippet:loadjson(‘snippets/nameofthesnippet.json’).
l
ForaHandlebarssnippet:see"HandlebarsinOLConnect"onpage763.
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1182and"loadjson()"onpage1184.
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1182formoreinformationaboutthisfunction.
Loadingasnippet,dependingonthevalueofadatafield
Toloadasnippetdependingonthevalueofadatafield,youhavetoaddaconditiontothescript.
Page 831