Manages Handlebars templates.
Methods
-
<static> compile(key, src)
-
Compiles a template.
This method caches the precompiled version of the template and returns the compiled template. The template can be accessed directly via
Handlebars.templates[key].Parameters:
Name Type Description keystring Identifier of the template to be compiled.
srcstring The actual template source to be compiled.
Returns:
The compiled template.
- Type
- function
-
<static> empty()
-
A precompiled empty template function.
Returns:
The empty string.
- Type
- string
-
<static> get(key [, compile])
-
Retrieves a compiled Handlebars template.
Parameters:
Name Type Argument Default Description keystring Identifier of the template to be retrieved.
compileboolean <optional>
true Force the template to compile if we have uncompiled source.
Returns:
The compiled template.
- Type
- function
-
<static> getField(type, view, module [, fallbackTemplate])
-
Gets the compiled template for a field.
Parameters:
Name Type Argument Default Description typestring Field type.
viewstring View name.
modulestring The module the field is from.
fallbackTemplateboolean <optional>
true Template name to fall back to if the template for
viewis not found.Returns:
The compiled template.
- Type
- function
-
<static> getLayout( [name] [, moduleName])
-
Gets the compiled template for a layout.
Parameters:
Name Type Argument Description namestring <optional>
Layout name.
moduleNamestring <optional>
Module name.
Returns:
The compiled template.
- Type
- function
-
<static> getView(name [, module])
-
Gets the compiled template for a view.
Parameters:
Name Type Argument Description namestring View name.
modulestring <optional>
Module name.
Returns:
The compiled template.
- Type
- function
-
<static> init()
-
Loads templates from local storage and populates the
Handlebars.templatescollection. -
<static> set(metadata [, force])
-
Registers view, layout, and field templates from metadata payload for later "lazy" on-demand compilation.
The metadata must contain the following sections:
{ // This should now be deprecated "view_templates": { "detail": HB template source, "list": HB template source, // etc. }, "sugarFields": { "text": { "templates": { "default": HB template source, "detail": HB template source, "edit": ..., "list": ... } }, "bool": { // templates for boolean field }, // etc. } "views": { "text": { "templates" { "view": HB template source... "view2": HB template source.. }. } }Parameters:
Name Type Argument Default Description metadataObject Metadata payload.
forceboolean <optional>
false Flag indicating if the cache is ignored and the templates are to be recompiled.
-
<static> setField(type, view, module, src [, force])
-
Compiles a field template and puts it into local storage.
Parameters:
Name Type Argument Default Description typestring Field type.
viewstring View name.
modulestring The module the field is from.
srcstring Template source code.
forceboolean <optional>
false Flag indicating if the template must be re-compiled.
Returns:
The compiled template.
- Type
- function
-
<static> setLayout(name [, moduleName], src [, force])
-
Compiles a layout template and puts it into local storage.
Parameters:
Name Type Argument Default Description namestring Layout name.
moduleNamestring <optional>
Module Name.
srcstring Template source code.
forceboolean <optional>
false Flag indicating if the template must be re-compiled.
Returns:
The compiled template.
- Type
- function
-
<static> setView(name, module, src [, force])
-
Compiles a view template and puts it into local storage.
Parameters:
Name Type Argument Default Description namestring View name.
modulestring Module name.
srcstring Template source code.
forceboolean <optional>
false Flag indicating if the template must be re-compiled.
Returns:
The compiled template.
- Type
- function