OpenWGA 7.5 - OpenWGA Concepts and Features

Design and development » WebTML » Features » Scriptlets

Custom scriptlet macros

The available scriptlet macros can be extended by defining additional macros in OpenWGA design.

A custom scriptlet macro is defined as TMLScript module in the design of an application. It must match the following conditions:

  • It must be stored in a system resources subfolder of folder "tmlscript" with name "wga/scriptlets"
  • The name of the file may not match the name of any other predefined scriplet macro

The code contained in the module is executed when the scriptlet is resolved. Whatever is returned via "return" statement will be embedded to the code at the position of the macro.

For example, imagine the following code stored in a file "scripts/tmlscript/wga/scriptlets/home.tmlscript" of your design:

return '<a href="' + context("name:home").contenturl() + '">Homepage</a>';


Once stored this macro is available to apps that use the design containing the module. Use it by specifying the name of the module (without prefix "scriptlets:") as macro name. So regarding the example the following may be used in the rich text editor:

This is a link to the homepage of this site: {@!home@}


The custom macro can also receive parameters, just like is possible for the predefined portlets. These are passed to the macro as WebTML variables "tmlparam1" to "tmlparam5" for parameters 1 to 5.

The following example macro creates a link to a file attachment to displayed in a separate browser window. The data about document, file name and title of the link are passed as parameters:

return '<a target="_blank" href="' + fileurl(tmlparam1, tmlparam2) + '">' + tmlparam3 + '</a>'


If this code is stored into a module "newwinlink.tmlscript" usage may look like this:

Link to {@!newwinlink: instructions, install.pdf, Installations Instructions@}



Since custom scriptlets have access to the full TMLScript language potential it is theoretically possible to offer dangerous functionalities to the author that way, which may endanger integrity of the data and runtime of OpenWGA. As all authors of any rich text fields have access to these macros the functionality offered here should be carefully chosen. Any data-modifying functionality should be avoided.