2019.2

Table Of Contents
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.
Other resources
There are also many resources online to help learn about JavaScript performance and coding
mistakes. See for example:
l JavaScript performance
l The 10 most common JavaScript mistakes
l Tips for writing efficient JavaScript.
Note that most resources on the web are about JavaScript in the browser, but the greatest
majority of the tips do, indeed, apply to scripts in general, wherever they are used.
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 page853) and in the
code use the following function:
loadhtml(‘snippets/nameofthesnippet.html’).
To insert the snippet in the content at any position where the script's selector is encountered,
write results.loadhtml('snippets/nameofthesnippet.html').
Make sure that the file name is exactly the same as the file in the Snippets folder. If the file
name isn’t correct, the snippet will not appear in the template.
To load a JSON snippet in script, use: loadjson(‘snippets/nameofthesnippet.json’).
Tip
To insert the code to load a snippet even quicker, you can:
Page 872