Loadhtml()
Global function that replaces the content (inner html) of each
matched element in the result set, alternatively load the data into
a variable. The location should be an URL or a relative file
path.
- loadhtml(location)
- loadhtml(location, selector)
Note! Loadhtml() is cached per batch run (based on the URL)
in print/email.
loadhtml(location)
Loads all html from the HTML file
- location string, can be absolute or relative to the section/context. Use: snippets/<snippet-name> to retrieve the content from a HTML file residing in snippets folder of the Resources panel.
Examples |
---|
Loads a local html snippet
(Resources panel) directly into the matched elements results.loadhtml("snippets/snippet.html"); |
Loads a local html snippet (Resources
panel) into a variable The replaceWith() command is used to replace the matched element with the contents of the snippet. var mysnippet = loadhtml('snippets/snippet.html'); results.replaceWith(mysnippet);
// Same result different notation results.replaceWith(loadhtml('snippets/snippet.html'));
|
Load a snippet into a variable
and find/replace text in the variable before injecting
the content into the page. Second find command adds formatting
to the replacement text var mysnippet = loadhtml('snippets/snippet.html'); mysnippet.find('@var1@').text('OL Connect 1'); mysnippet.find('@var2@').html('<i>OL Connect 2</i>').css('text-decoration','underline'); results.replaceWith(mysnippet); |
Load a snippet into a variable
and retrieve an element from the snippet using query() var mysnippet = loadhtml('snippets/text-root-wrapped.html'); var subject = query("#subject", mysnippet).text(); results.append("<p style='font-weight: bold;'>" + subject + "</p>"); |
loadhtml(location, selector)
Retrieve specific content from the filename.
- location string, can be absolute or relative to the section/context. Use: snippets/<snippet-name> to retrieve the content from a HTML file residing in snippets folder of the Resources panel.
- selector string, the supplied selector should conform to CSS selector syntax and allows you to retrieve only the content of matching elements.
Examples |
---|
// Load a specific element from the snippet var mysnippet = loadhtml('snippets/snippet-selectors.html','#item3'); results.replaceWith(mysnippet); |
Load the children of the selected element var snippet = loadhtml('snippets/snippet.html','foobar').children(); results.replaceWith(snippet); |