Reference Global Functions in an Expression
For the layout that defines the
commonUtils
and dateLocalUtils
modules (see example definition in Define Global Functions in an Extension), the following expressions can be used to call the methods exposed by a particular global functions module:
$layout.modules.commonUtils.titleCase()
$layout.modules.dateLocalUtils.dateToIsoString()
Where titleCase
and dateToIsoString
are the function names defined in the extension's functions.json
.
Note:
$modules
is the shortened form for use in the current container. Any container that imports modules can expect $modules
to be available (for example, $page.modules
and $fragment.modules
).
A JavaScript action chain can provide $modules
as part of the context:
class MyChain extends ActionChain {
async run(context, params) {
context.$layout.modules.dateUtils.today();
const result = context.$application.modules.appUtils.update(); // can also call modules in parent scopes
await Actions.assignVariable(context,
{
variable: '$layout.variables.someValue',
value: result / 2,
});
}
}