2022.2

Table Of Contents
activeSection.background.position = MediaPosition.FIT_TO_MEDIA;
Dynamicallyaddingsections(cloning)
Thistopicexplainshowto"clone"(copy)asectioninaControlScript.Printsectionscanbecloned,so
thatadocumentcanhaveadynamicnumberofsections,basedondata.Thisisparticularlyuseful
whentherecordsetdefinesoneormorePDFs(e.g.insurancepolicies)perrecipient.ViaaControl
Script,foreachPDFasectioncanbeclonedandeachclonecanbegivenoneofthePDFsasback-
ground(see"ControlScript:SettingaPrintsection'sbackground"onpage404).Foreachpageinthe
PDF,apagewillbeaddedtothesection.
ForinformationaboutControlScriptsingeneral,see"ControlScripts"onpage398and"ControlScript
API"onpage815.Ifyoudon'tknowhowtowritescripts,see"Writingyourownscripts"onpage368.
Note: Clonesareonlyvisibleintheoutput,notonthePreviewtab.
Cloning a section
Tocloneasection,firstusetheclone()functionandthenaddtheclonetothePrintcontextbeforeor
afteraspecificsection,usingaddAfter()oraddBefore():
var printSections = merge.template.contexts.PRINT.sections;
var clone = printSections["Section 1"].clone();
printSections["Section 1"].addAfter(clone);
Clonedsectionshavethesamepropertiesasnormalsections(see"section"onpage848),butthey
cannotcallthesectionfunctionsclone(),addBefore()andaddAfter(),whichmeansyoucannot
cloneaclone,oruseacloneasastartingpointtoinsertotherclonesintoatemplate.
Notethatwithmultipleclones,thenextcloneisalwaysaddedafterthepreviousclone.
WithaddBefore(),thecodeoriginal.addBefore(clone1); original.addBefore
(clone2);willresultin"clone1,clone2,original".
WithaddAfter()thecodeoriginal.addAfter(clone1); original.addAfter(clone2);
resultsin"original,clone1,clone2".
Renaming a clone
Bydefault,clonesreceivethenameoftheirsourcesectionwitha"Clone{uniqueidentifier}"suffix,for
example:
Source:"Section1"
CloneName:"Section1Clone71c3e414-fdf3-11e8-8eb2-f2801f1b9fd1"
Usethenamepropertytoassignanothernametotheclonedsection,forexample:
Page 406