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 key
string Identifier of the template to be compiled.
src
string 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 key
string Identifier of the template to be retrieved.
compile
boolean <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 type
string Field type.
view
string View name.
module
string The module the field is from.
fallbackTemplate
boolean <optional>
true Template name to fall back to if the template for
view
is not found.Returns:
The compiled template.
- Type
- function
-
<static> getLayout( [name] [, moduleName])
-
Gets the compiled template for a layout.
Parameters:
Name Type Argument Description name
string <optional>
Layout name.
moduleName
string <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 name
string View name.
module
string <optional>
Module name.
Returns:
The compiled template.
- Type
- function
-
<static> init()
-
Loads templates from local storage and populates the
Handlebars.templates
collection. -
<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 metadata
Object Metadata payload.
force
boolean <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 type
string Field type.
view
string View name.
module
string The module the field is from.
src
string Template source code.
force
boolean <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 name
string Layout name.
moduleName
string <optional>
Module Name.
src
string Template source code.
force
boolean <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 name
string View name.
module
string Module name.
src
string Template source code.
force
boolean <optional>
false Flag indicating if the template must be re-compiled.
Returns:
The compiled template.
- Type
- function