2021.1

Table Of Contents
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 page732).
It is also possible to include content that is served by another server. Many servers provide an
API to fetch publicly available content from their site. That content may even be dynamic: the
most recent blog posts on a Wordpress website, for example, or the current weather forecast
for a certain city.
This topic explains how to retrieve content using a server's API and insert that content in a
template.
Step 1: Getting the appropriate link
To request content from another server, you will need a link.
Some websites give the option to embed their content in your website by providing a link or the
complete HTML. Youtube.com, for example, offers not only a link to share a certain video, but
also the full HTML to embed that video in your website.
If that option is not available, you will have to build the link yourself. Find the server's API and
look through it to get the exact endpoint and parameters that you need.
With many servers it is required to use an API key in the link; this key generally comes for free
after you sign up to their website. The key will be part of the link that is used to make a request
to the server.
Note
Pay attention to the service's Terms of Service. Many servers have limitations on the
number of calls that can be made to them for free. Beyond these limits, their content will
not show up in your template unless you purchase a business plan.
Page 897