2022.1

Table Of Contents
Create a script (see "Writing your own scripts" on page918). In the code use the following
function:
l For an HTML snippet: loadhtml(‘snippets/nameofthesnippet.html’).
To insert the snippet in the content at any position where the script's selector is
encountered, write results.loadhtml('snippets/nameofthesnippet.html').
Make sure that the file name is exactly the same as the file in the Snippets folder. If the
file name isn’t correct, the snippet will not appear in the template.
l For a JSON snippet: loadjson(‘snippets/nameofthesnippet.json’).
l For a Handlebars snippet: see "Handlebars in OL Connect" on page978.
Tip
To insert the code to load a snippet even quicker, you can:
l Drag a snippet into the Script window. The function that loads the script -
loadhtml() or loadjson(), depending on the file type - will automatically be
added, including the file name.
l Right-click a snippet and select Copy Resource Location to copy the relative
path of the snippet to the clipboard. It may then be pasted into a script.
Remote snippets are retrieved in the same way, except that the file extension should be
.rhtml instead of .html. If it is a remote JSON snippet, the file extension is .rjson.
Again, note that the name of the snippet must be exactly the same as in the Snippets folder.
For more examples, see "loadhtml()" on page1358 and "loadjson()" on page1361.
Loading part of an HTML snippet
When a snippet contains a part that can be identified by a selector, that selector can be used to
load that part of the snippet into a template.
In script, use the following code:
results.loadhtml(snippets/nameofthesnippet.html, selector)
See "loadhtml()" on page1358 for more information about this function.
Page 946