1.7

Table Of Contents
Example
The following script replaces all of the placeholders on a postcard. It takes advantage of the
JavaScript replace() command. Assuming that the ID of the block that requires personalization
is promoblock, the script has to have its selector set to #promoblock.
var block = results.html();
var data = record.fields;
block = block.replace('@name@',data.first + ' ' + data.last);
block = block.replace('@address@',data.address);
block = block.replace('@zip@',data.zip);
block = block.replace('@city@',data.city);
block = block.replace('@country@',data.country);
block = block.replace('@saldo@',data.saldo);
block = block.replace('@promo@',data.promo);
block = block.replace('@customercode@', data.customercode);
results.html(block);
The first line retrieves the HTML of the promo block and stores it in a variable called block. To
make the code more readible, the fields from the record are stored in a variable named data.
After replacing the placeholders by values, the script replaces the HTML of the promoblock with
the personalized string.
Loading a snippet via a script
Instead of dragging it into the content directly, it is possible, and often very useful, to load a
snippet dynamically. Create a script (see "Writing your own scripts" on page552) and in the
code, use the following function:
results.loadhtml(‘snippets/nameofthesnippet.html)
Remote snippets are retrieved in the same way, except that the file extension should be .rhtml
instead of .html.
Note that the name of the snippet must be exactly the same as in the Snippets folder.
This function will insert the snippet in the content at any position where the script's selector is
encountered.
For more examples, see "loadhtml()" on page799.
Page 568