Class HandlebarsJs

  • public abstract class HandlebarsJs
    extends Object
    The main motivation of HandlebarsJs is the ability of reuse JavaScript helpers in the server and the client.
    • Method Detail

      • registerHelpers

        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 ' +;
          Handlebars.registerHelper('hey', function (context, options) {
            return 'Hi ' + + options.hash['x'];
          Handlebars.registerHelper('hey', function (context, p1, p2, options) {
            return 'Hi ' + + 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.
      • createRhino

        public static HandlebarsJs createRhino​(HelperRegistry helperRegistry,
                                               int optimizationLevel)
        Creates a HandlebarsJs object.
        helperRegistry - The helperRegistry object. Required.
        optimizationLevel - The optimization level of rhino.
        A new HandlebarsJs object.