Handlebars API
This topic lists the functions of Handlebars that are supported in Designer scripts. It also lists features that are unsupported in OL Connect.
Functions
compile('template') |
Compiles the specified Handlebars template* into a function that can be called with data. For example:
Note: Passing options is not supported in OL Connect. |
render('template', data) |
Renders a specified Handlebars template.* If data is passed, that data is used to render the template. Handlebars.render( "snippets/Template.hbs" ) The result of this function is HTML. See also: Handlebars templates. |
registerPartial('name', 'template') |
Registers a template* as a partial with the specified name. The partial can then be referred to by its name in Handlebars templates as well as functions using {{> partialName}}. For example: {{> clauses}}. See: Partials. |
registerHelper() |
Registers a function as helper with the specified name. Note: Registering multiple helpers with a single call is not supported. See: Handlebars expressions. |
escapeHTML() |
HTML-escapes the supplied string. This means that those characters that have a special function in HTML: & < > \" ' ` = are replaced with HTML character references. For example: & will be changed into &. See: HTML values. |
* In all these functions, 'template' can be:
- the name of an .hbs snippet in the template (for example:
{{> snippets/Snippet 1.hbs}}
- the name of an .hbs snippet on disk (starting with file:///)
- the name of a remote .hbs snippet (starting with http:// or https://)
- a string that contains HTML and Handlebars expressions.
With a snippet on disk, the complete syntax is: file://<host>/<path>. If the host is "localhost", it can be omitted, resulting in file:///<path> - note the three forward slashes after file:.
In the remainder of the path you can either use escaped backward slashes:
"file:///C:\\Users\\Administrator\\Desktop\\Handlebars_LoadFile.hbs"
or forward slashes:
"file:///C:/Users/Administrator/Desktop/Handlebars_LoadFile.hbs"
loadhtml()
in Handlebars functions. HTML with Handlebars expressions is not necessarily valid HTML. Processing it with an HTML parser might break both the Handlebars expressions and the HTML.Unsupported features
The following features are not supported in Handlebars templates in OL Connect:
-
The
SafeString
class. It is not needed since the result of a block helper is not HTML-escaped in OL Connect. -
Inline escapes.
-
Raw block helpers.
-
Passing options when compiling a Handlebars template.
The following Handlebars partials features are not supported in OL Connect.
-
Registering multiple partials with a single call.
-
Passing a custom context as a parameter.
-
Passing hash parameters (seehttps://devdocs.io/handlebars/partials#partial-parameters).
The following Handlebars helpers features are not supported in OL Connect.
-
The
lookup
helper andlog
block helper. -
The data variable @key. OL Connect only supports iterating over arrays and tables, not over arbitrary objects.
-
Registering multiple helpers with a single call.
-
The
blockHelperMissing
andhelperMissing
hooks. -
Passing
options.hash
,options.helpers
andoptions.partials
arguments to helpers. (options.data
,options.fn
andoptions.inverse
are supported.)