2021.1

Table Of Contents
Example
The following script evaluates if the value of the LANGUAGE field in the record is ‘En’. If so, the
snippet is added to the content.
if (record.fields.LANGUAGE == En’) {
results.loadhtml(snippets/nameofthesnippet.html);
}
Another example is given in a how-to; see Load a snippet based on a data field value.
Loading part of a snippet, based on the value of a data field
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. It is possible to do this, based on the value of the
data field. This is easiest when the selector matches the value of a data field.
Example
The following script reads the value of the LANGUAGE field in the record and uses that value
as the selector in the function loadhtml(). If the snippet contains an HTML element with this ID
(for example, <p ID=”En”>), that HTML element will be added to the content:
var language = record.fields.LANGUAGE;
results.loadhtml(snippets/nameofthesnippet.html, #+ language)
Another example is given in the following how-to: Using a selector to load part of a snippet.
See also: "Standard Script API" on page1273.
Tip
An easy way to group content in a snippet is putting each part in a container and giving
that container an ID, for example:
<div ID=”EN><p>This is text for English customers.</p></div>
Use the function .children() to load the contents of the container, and not the container
itself. For example:
results.loadhtml(Snippets/myfooter.html’, #EN).children()
This script loads the paragraph of the example (<p>), but not the container itself (<div>).
Page 896