public abstract class HandlebarsJs extends Object
HandlebarsJs is the ability of reuse JavaScript helpers in the
server and the client.| Modifier and Type | Field and Description |
|---|---|
protected HelperRegistry |
registry
The handlebars instance.
|
| Constructor and Description |
|---|
HandlebarsJs(HelperRegistry helperRegistry)
Creates a new
HelperRegistry object. |
| Modifier and Type | Method and Description |
|---|---|
static HandlebarsJs |
create(HelperRegistry helperRegistry)
Creates a
HandlebarsJs object. |
abstract void |
registerHelpers(String filename,
String source)
Register helpers from a JavaScript source.
|
protected final HelperRegistry registry
public HandlebarsJs(HelperRegistry helperRegistry)
HelperRegistry object.helperRegistry - The HelperRegistry instance. Required.public abstract void registerHelpers(String filename, String source) throws Exception
Register helpers from a JavaScript source.
A JavaScript source file looks like:
Handlebars.registerHelper('hey', function (context) {
return 'Hi ' + context.name;
});
...
Handlebars.registerHelper('hey', function (context, options) {
return 'Hi ' + context.name + options.hash['x'];
});
...
Handlebars.registerHelper('hey', function (context, p1, p2, options) {
return 'Hi ' + context.name + p1 + p2 + options.hash['x'];
});
...
To keep your helpers reusable between server and client avoid DOM manipulation.filename - The file name (just for debugging purpose). Required.source - The JavaScript source. Required.Exception - If the JavaScript helpers can't be registered.public static HandlebarsJs create(HelperRegistry helperRegistry)
HandlebarsJs object.helperRegistry - The helperRegistry object. Required.HandlebarsJs object.Copyright © 2015. All rights reserved.