1.4

Examples
Replace elements with a snippet
The following script loads a snippet and then replaces the elements matched by the script's
selector with the snippet.
var snippet = loadhtml('snippets/mysnippet.html');
results.replaceWith(snippet);
Replace elements with a set of snippets
The following script loads snippets and adds their elements to a new, empty result set (using
query()). Then it replaces a placeholder in the template with the set of snippets.
var chapters = query();
for ( var i = 1; i <= 4; i++) {
chapters = chapters.add(loadhtml('snippets/Chapter' + i +
'.html'));
}
results.replaceWith(chapters);
Control Script API
When output is generated from a template, Control Scripts run before all other scripts. This topic
lists features that can only be used in Control Scripts and provides some sample scripts. See
"Control Scripts" on page 208 for more information about how to use this kind of scripts.
Objects available to pre-merge scripts
Channel
This is an enumeration for the output channels. The active output channel is registered in
merge.channel.
Value Description
EMAIL The merge request is for output to Email
PRINT The merge request is for output to Print
WEB The merge request is for output to Web
THUMBNAIL The merge request is for generating a template preview
Page 61