Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 3.1 KB

handlebars.md

File metadata and controls

57 lines (46 loc) · 3.1 KB

fluid.express.hb

This component adds Handlebars rendering support to a fluid.express instance. As with any custom Express view engine, this component provides a renderer that can be used with the Express Response object's render method.

This component is meant to be a direct child of a fluid.express instance, as shown here:

fluid.defaults("my.grade.name", {
    gradeNames: ["fluid.express"],
    port: 9090,
    components: {
        hb: {
            type: "fluid.express.hb",
            options: {
                templateDirs: {
                    handlebars: "%fluid-handlebars/src/templates",
                    myPackage: {
                        path: "%my-package/src/templates",
                        priority: "before:handlebars"
                    }
                }
            }
        }
    }

});

my.grade.name();

Component Options

Option Type Description
templateDirs {Array} or {String} A list of template directories that contain handlebars layouts, pages, and partials. These can either be full paths or (better) paths relative to a particular package, as in %fluid-handlebars/src/templates.
messageBundleDirs {Array} or {String} A list of directories that contain message bundles (see the i18n docs for details). These can either be full paths or (better) paths relative to a particular package, as in %fluid-handlebars/src/templates.

To use this middleware, you need to make it aware of one or more directories that contain templates (typically via the options.config.express.views option in your fluid.express configuration). These options are passed to the underlying renderer component, see those docs for details.

fluid.express.hb.live

This component grade extends fluid.express.hb and adds support for "live" reloading of templates. It uses an instance of fluid.handlebars.watcher to watch for changes to all directories specified in options.templateDirs see above. Whenever files are added, removed, or changed, the renderer's cache will be cleared and all partials will be reloaded. This process typically takes around two seconds, mainly because we wait to be sure the template has been completely saved to disc. See the fluid.handlebars.watcher docs for details.

Note that this grade takes care of reloading templates in the view engine. The error rendering middleware, single template middleware and "dispatcher" all use the view engine, and do not need to be notified of updates separately. The "inline" middleware that delivers template content to client-side components does not use the view engine, and needs to be explicitly told to reload its template content. See the "inline" middleware documentation for details.