Skip to content

Latest commit

 

History

History
77 lines (66 loc) · 2.56 KB

inline.md

File metadata and controls

77 lines (66 loc) · 2.56 KB

fluid.handlebars.inlineTemplateBundlingMiddleware

Middleware that combines all available Handlebars templates into a single bundle that can be downloaded and used by the client-side renderer.

Say that we have a views directory that contains the following content:

  • views/pages/main.handlebars
  • views/pages/alternate.handlebars
  • views/layouts/main.handlebars
  • views/partials/gewgaw.handlebars

If this middleware were configured to use the views directory, it would return a payload like the following:

{
    "pages": {
        "main": "<p>Howdy.</p>",
        "alternate": "<p>{{>gewgaw}}</p>"
    },
    "layouts": {
        "main": "<html><body>{{body}}<body></html>"
    },
    "partials": {
        "gewgaw": "*insert bells and whistles*"
    }
}

The client-side renderer.md can work with this format and ensure that (for example) all partials are available and that the right layout is used.

Component Options

Option Type Description
templateDirs `Array String`

Live Reloading

This middleware component provides a loadTemplates event that can be used to reload all template content from the filesystem. The component itself only makes use of this event on startup. To enable "live" reloading, you will need to fire the loadTemplates event whenever an associated "watcher" component detects a change, as in the following example:

fluid.defaults("my.live.express", {
    gradeNames: ["fluid.express"],
    events: {
        onFsChange: null
    },
    listeners: {
        "onFsChange.reloadInlineTemplates": {
            func: "{inlineMiddleware}.events.loadTemplates.fire"
        }
    },
    components: {
        handlebars: {
            type: "fluid.express.hb.live",
            options: {
                templateDirs: "{my.live.express}.options.templateDirs",
                listeners: {
                    "onFsChange.notifyExpress": {
                        func: "{my.live.express}.events.onFsChange.fire"
                    }
                }
            }
        },
        inlineMiddleware: {
            type: "fluid.handlebars.inlineTemplateBundlingMiddleware",
            options: {
                templateDirs: "{my.live.express}.options.templateDirs"
            }
        }
    }
});