/workspace/getTemplate

The module exports the getTemplate method which is required by the query, languageTemplates, getLayer, and getLocale modules.

Requires

Methods

(async, inner) cacheTemplate(workspace, template, responseopt) → {Promise.<(Object|Error)>}

The method assigns the response object to the template object and removes the src property.

This effectively caches the template since the src to fetch the template is removed.

A src property is assigned as key for an object without an key property.

This allows to cache templates which should be merged into their respective parent objects.

A src property beginning with file: is not removed since file resources do not require caching.

Parameters:
NameTypeAttributesDescription
workspaceworkspace
templateobject
responseobject<optional>

An object from a template src

Returns:

JSON Template

Type: 
Promise.<(Object|Error)>

(async, inner) getTemplate(key) → {Promise.<(Object|Error)>}

The workspace will be checked and cached by the Workspace API checkWorkspaceCache method.

A JSON template object will be requested from the getTemplateObject method.

An error will be returned if the lookup failed.

A template will be fetched from the templates src property.

A template can be cached by removing the src property in the workspace.templates.

The key will be assigned to the template object as key property.

Parameters:
NameTypeDescription
keystring
Returns:

JSON Template

Type: 
Promise.<(Object|Error)>

(async, inner) getTemplateObject(template) → {Promise.<(Object|Error)>}

A template object matching the template_key param in the workspace.templates{} object will be returned.

The template string will be checked to include only whitelisted characters.

An error exception will be returned if the template object lookup from the workspace failed.

Parameters:
NameTypeDescription
templatestring
Returns:

JSON Template

Type: 
Promise.<(Object|Error)>

(async, inner) moduleTemplate(template, response) → {Promise.<(Object|Error)>}

The script string is converted to a JavaScript data URL which can be used in a dynamic ESM import.

The default export or the imported module itself will be assigned as the render method in the module template.

Module templates are not cached.

Parameters:
NameTypeDescription
templateobject
responsestring

Module script as string.

Returns:

JSON Template

Type: 
Promise.<(Object|Error)>