2019.1

Table Of Contents
To learn how to put a placeholder or placeholders inside an element that has an ID, see
"Boxes" on page668. To use that ID as the script's selector: double-click the script in the
Scripts pane and change the Find method to Selector and Text, or to Selector if the
placeholder is the only content of the container. Enter the ID of the wrapper element in the
Selector field, preceded by #, for example: #firstname.
Tip
When using the drag-and-drop method to insert data fields in a template:
l
Press the Alt key while dragging, to wrap the placeholder in a span, give the span
an ID and have that ID used as the script's selector.
l
Press the Ctrl key while dragging, to wrap the placeholder in an absolute
positioned box (a div) at the cursor position. A unique ID is assigned to the box and
used as the script's selector.
Avoid DOM manipulations
The Scripting API of the Designer is a very powerful tool to manipulate and personalize your
document. But keep in mind that DOM manipulation commands like append(), prepend(),
before() and after() are resource intensive.
Try avoiding DOM modifications, especially within loops. Storing the content in a variable and
appending the information after the loop is more efficient: this way, the template will be touched
only once.
Example
The following example loads a snippet into a variable and uses the find() and text() commands
of the Designer scripting API.
var labelElm = loadhtml('snippets/label.html');
for(var i = 0; i < record.tables.products.length; i++) {
var label = labelElm.clone();
label.find('@ProductLabel@').text(record.tables.products
[i].ProductDescription);
results.after(label);
}
Page 812