2022.1

Table Of Contents
Dynamically adding sections (cloning)
This topic explains how to "clone" (copy) a section in a Control Script. Print sections can be
cloned, so that a document can have a dynamic number of sections, based on data. This is
particularly useful when the record set defines one or more PDFs (e.g. insurance policies) per
recipient. Via a Control Script, for each PDF a section can be cloned and each clone can be
given one of the PDFs as background (see "Control Script: Setting a Print section's
background" on page963). For each page in the PDF, a page will be added to the section.
For information about Control Scripts in general, see "Control Scripts" on page954 and
"Control Script API" on page1466. If you don't know how to write scripts, see "Writing your own
scripts" on page918.
Note
Clones are only visible in the output, not on the Preview tab.
Cloning a section
To clone a section, first use the clone() function and then add the clone to the Print context
before or after a specific section, using addAfter() or addBefore():
var printSections = merge.template.contexts.PRINT.sections;
var clone = printSections["Section 1"].clone();
printSections["Section 1"].addAfter(clone);
Cloned sections have the same properties as normal sections (see "section" on page1515),
but they cannot call the section functions clone(), addBefore() and addAfter(), which means
you cannot clone a clone, or use a clone as a starting point to insert other clones into a
template.
Note that with multiple clones, the next clone is always added after the previous clone.
With addBefore(), the code original.addBefore(clone1); original.addBefore(clone2); will
result in "clone1, clone2, original".
With addAfter() the code original.addAfter(clone1); original.addAfter(clone2); results
in "original, clone1, clone2".
Page 966