2020.2

Table Of Contents
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1267.
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>).
Load a snippet and insert variable data into it
The following script loads part of a snippet based on the value of a field, and then
finds/replaces text by the value of a field before inserting the content into the document.
var promoTxt = loadhtml('snippets/promo-en.html', '#' +
record.fields['YOGA']);
promoTxt.find('@first@').text(record.fields['FIRSTNAME']);
results.html(promoTxt);
Loading content using a server's API
Content in a template is usually static (apart from being personalized) and part of the main text
flow. It can also be located in a snippet (see "Snippets" on page722).
It is also possible to include content that is served by another server. Many servers provide an
Page 883