Managing scripts
Changing the order of execution
When a record set is merged with a template to generate output, all scripts are executed once for every record in the record set, in the order in which they appear in the Scripts pane at the bottom left.
The order in which scripts are executed is particularly important when one script produces content that contains a selector for another script. If the other script has already been executed, it will not run again automatically. So, scripts that produce content that contains one or more selectors for other scripts, need to come first.
To change the order in which scripts are executed:
- Click a script or a folder in the Scripts pane at the bottom. Drag it up or down and drop it.
Note: Control scripts are always executed first, regardless of where they are in the Scripts pane. They can not be excluded from execution for a specific context or section, using the execution scope of a folder; see Execution scope. What you can do is disable the script or the containing folder; see Enable/disable scripts.
Script folders
Scripts can be organized in folders. Why would you do that? For three reasons:
-
Folders have an execution scope. You can specify for which contexts and sections the scripts in a folder have to run.
-
Folders provide a better overview than a long unorganized list of scripts.
-
Folders make it easier to change the order of execution for a bunch of scripts (see: Changing the order of execution to learn why the order of execution is important). Dragging a folder up or down will cause all the scripts in that folder to be executed earlier or later, respectively.
To make a new folder on the Scripts pane:
-
In the Scripts pane, click the black triangle on the New button.
-
Click Folder. The folder will appear in the list of scripts.
-
Change the name of the new folder: right-click the folder and click Rename.
-
Drag scripts to the folder.
Tip: It may be helpful to put scripts that have an effect on the same context or section in one folder, because you can set the execution scope of scripts per folder (see: Execution scope).
Note: Control scripts are always executed first, regardless of where they are in the Scripts pane. They can not be excluded from execution for a specific context or section, using the execution scope of a folder; see Execution scope. What you can do is disable the script or the containing folder; see Enable/disable scripts.
Execution scope
A particular script may be used in one context or section, but not in other contexts or sections. Nevertheless, when processing the template, the Designer tries to find the selector of each script in all contexts and sections – unless the script is located in a scripts folder for which the execution scope has been set to the relevant contexts or sections. So, setting the execution scope of a folder saves processing time.
To change the execution scope of a script:
-
Put the script in a folder; see Script folders.
-
Right-click the folder, and then click Properties.
-
Check the contexts and sections for which the scripts in this folder should run.
Note: Control scripts are always executed first, regardless of where they are in the Scripts pane. They can not be excluded from execution for a specific context or section, using the execution scope of a folder; see Execution scope. What you can do is disable the script or the containing folder; see Enable/disable scripts.
Tip: For more ways to optimize scripts, see Optimizing scripts.
Enable/disable scripts
A disabled script will not run at all when the template is merged with a record set to generate output. Disabling script execution in certain contexts or sections helps with performance, since scripts normally run, whether or not their placeholder or selector is present in your template. It is highly recommended to disable any script that is not relevant to specific sections or contexts.
When you disable a folder, all scripts in the folder will be disabled.
To enable or disable a script or a folder:
-
On the Scripts pane, right-click the script or the folder and click Disable (if the script or folder was enabled) or Enable (if the script or folder was disabled).
If all scripts in a folder are disabled, the folder itself will also be grayed out.
Tip: For more ways to optimize scripts, see Optimizing scripts.
Import/export scripts
The easiest way to import scripts into another template is to open the template and use the Import Resources dialog; see Import Resources dialog.
Remember also to import or add any files that a script refers to.
Alternatively, scripts can be exported or imported via the Scripts pane.
To export a script:
On the Scripts pane, click on a script, click the View Menu button and then click Export.
Or, right-click a script and select Export.Give the script a name and click OK.
- On the Scripts pane, click the View Menu button and then click Import. Find the script and click OK
Files that a script may refer to, such as images, snippets and fonts, are not exported or imported together with a script.
Test the script to make sure that all files are present in the template and that the script's selector matches something in the content of the template; see Testing scripts.