Scaffold extentions
The Scaffold system provides a robust way of extending the base JavaScript class by adding what are called ‘Extensions’.These extensions are simply functions that you create in Scaffold and which are included in the Scaffold template scripts.
Besides allowing you to manage all your JavaScript code in a central area, an additional advantage to using extensions is that they can be shared across your entire template (or organisation) or across all your components – basically you need only to write it once, attach it to wherever you want, and once attached it will be added to the template scripts.
You have the option of creating extensions that target the three main areas of Scaffold – the Rich Content Editor (RCE), the website client, or the mobile client. Note that any extension targeted towards the website client will also be available to the mobile client by default.
Adding Extensions
You can add your own Extensions by navigating to the Extensions area of the Scaffold manager and clicking on the round blue button that has a plus symbol in the bottom right.
This will take you to the Add Extension form.
Give the Extension a name that you will be able to identify.
Provide the Function Declaration. This is the JavaScript function name and should have no spaces or special characters other than an underscore. This declaration will be what you will use to call the function in your other code (see next section for examples).
Specify a build target. This determines what file your function will be included in. You can target the Editor, the Web/Mobile Client, the Mobile Only Client, or all three.
If needed, provide the Function Parameters that will be used in calling your function. This is a simple comma separated list of variables; e.g.“e, clientid”. You will then have those variables available in the function body.
Set the Extension to active if you are ready (you can change this later if needed). Note that if it is not Active, it will not be added to any JavaScript file. Also be aware that changing the status does not impact already Live scripts that have been built – you will need to press the “Build Files” button on each template to have this change reflected.
You also have the ability to flag if this function is an async function or not. This is needed if you plan on using the ‘await’ keyword in your function body.
The last field is the Code field, which will contain the function body. You can add any legitimate JavaScript into this body, but note that all code will be in its own scope – you will not be able to call functions nor access variables outside of this function unless they are global.
Attaching Extensions
Once your Extensions are ready, you can then attach them to your Scaffold templates. To do this, navigate to the template page and look for the section marked ‘Extensions’
To attach your Extensions to your template, click on the blue button with a plus symbol on it. This will open a panel on the right-hand side of the page that has all the available Extensions you are allowed to attach.
If you want to attach all the Extensions that are listed, simply click on the top button to move all extensions.
Alternatively, you can click on each Extension you want and click on the second button to add only those you have selected.
Removing Extensions are similar with the third button used to remove selected items, and the last button to remove all.
Once ready, use the “Attach” button to save your selection.
To remove an extension from your template, under the Extension section, click on the unlink button on the Extension you want to remove.