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.

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:

  1. In the Scripts pane, click the black triangle on the New button.
  2. Click Folder. The folder will appear in the list of scripts.
  3. Change the name of the new folder: right-click the folder and click Rename.
  4. Drag scripts to the folder.

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).

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:

  1. Put the script in a folder; see Script folders.
  2. Right-click the folder, and then click Properties.
  3. Check the contexts and sections for which the scripts in this folder should run.

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.

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).
For more ways to optimize scripts, see Optimizing scripts.

Import/export scripts

Scripts can be exported - one at a time - for use in other templates. To do this:

  1. On the Scripts pane, click on a script, and then click the Export button, or right-click a script and select Export.
  2. Give the script a name and click OK.

To import a script in a template:

  • On the Scripts pane, click the Import button. 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.

 
  • Last Topic Update: 14, November, 2017 10:14 AM
  • Last Published: 23, May, 2019 01:55 PM