1.8

Table Of Contents
Note that interactive content, such as an interactive map, can only be used in Web templates,
and cannot be output on Print or Email contexts (even though they will show up in Preview
mode!).
Step 3: Writing a script
The final step is to write a script that retrieves the content and inserts it into the template (see
"Writing your own scripts" on page624). Use the element or the ID of the element that you
added in Step 2 as the script's selector. For information about selectors, see "Selectors in
Connect" on page660.
Tip
Select an element, then click on 'ID' in the Attributes pane, to create a script that has that element's
ID as selector.
Retrieving content
Depending on the type of content that the remote server returns - HTML or JSON - you can use
loadhtml(location) or loadjson(location) (see also: "loadhtml()" on page920 and "loadjson
()" on page922) to retrieve the content. The link that you selected in Step 1 should be passed
to the function as a string. For example:
loadjson('https://blog.mozilla.org/wp-json/wp/v2/posts?per_
page=5');
If the returned content is JSON data, that data may have to be wrapped in HTML before
inserting it into the template. This is demonstrated in the example below.
Tip
Install the Postman application to preview JSON returned by an endpoint.
Inserting content in the template
To insert the content after the selected element, use results.after(). To replace the element
with the new content, use results.html() or results.replaceWith().
Page 644