2020.2

Table Of Contents
The following script selects three boxes that all have the class box (selector: .box). It loops over
them, inserting as many products from an array as possible into the box. In fact, it inserts one
too many and removes the last one before moving on to the next box.
var products =
["Appetizer","Beans","Beef","Lettuce","Sprouts","Coconut","Juice","
Soup","Coriander","Cheese","Pasta","Sugar","Vinegar","Bread"];
var i = 0;
results.each( function() {
// Add elements to the box until it overflows.
while ( ! this.overflows() && i < products.length ) {
this.append("<p>" + products[i] + "</p>");
i++;
}
// Go one step back unless we processed all items in our array.
if( i < products.length ) {
query("p:last-child", this).remove();
i--;
}
});
section
The section object can be used to query and modify how the section (and the related context)
will be outputted. It is one of the most important objects in Control Scripts (see "Control Scripts"
on page890 and "Control Script API" on page1379).
Retrieving a section
A section can be retrieved using merge.template.contexts.ContextType.sections["section
name"], for example: merge.template.contexts.PRINT.sections["Section EN"].
A section can also be retrieved via merge.context.sections['section name']. Remember,
however, that when several contexts need to be merged (for example, when the Print context is
attached to an email), the script needs to check if the current context is of the type that contains
the desired section (for example: if (merge.context.type == ContextType.PRINT) {}). When
sections in different contexts have the same name, it is safer to use
merge.template.contexts.ContextType.sections["section name"].
Page 1426