Use Global Functions in a Container
Global functions must be imported into a page (or any Visual Builder container) using the imports
section of the container metadata (and its modules
property) before the global functions can be used.
For example, a layout.json
, defined in the same extension (ext-layout) where the functions metadata is defined, can specify the modules in its imports like this:
{
"imports": {
"modules": {
"utils": {
"path": "self:$functions/utils"
},
"dateUtils": {
"path": "self:$functions/dateLocalUtils"
},
"commonUtils": {
"path": "ext-common:$functions/utils"
}
}
}
}
The path
property uses a scheme for locating the JavaScript resource, particularly functions, using a convention with three elements:
{extId}:{resourceType}/{resourceAlias}
The path resolves to the actual require path to the JavaScript module loader.
Element | Description |
---|---|
{extId} |
Refers to the extension the resource belongs to.
|
{resourceType} |
Uses a special keyword for the
|
{resourceAlias} |
For global functions,
|
Here is an example of how functions.json
, defined under ext-common/ui/self/resources/functions
, might look:
{
"commonUtils": {
"path": "utils/common",
"label": "Common Utility Functions",
"referenceable": "extension",
"functions": {
"titleCase": {}
}
}
}
Note:
For "ext-layout" to import global functions from "ext-common", it must have a dependency on the "ext-common" (see below).