Note: This method is async; meaning that the directory is walked in a non-blocking manner to app startup.

Exposing locals as template data

hbs has the ability to expose the application and request locals within any context inside a view. To enable this functionality, simply call the localsAsTemplateData method and pass in your Express application instance.

Each instance has the same methods/properties as the hbs module object. The module object is actually just an instance created for you automatically.

extra scripts or styles

Sometimes it is useful to have custom scripts or stylesheets on your pages. Handlebars does not provide a way to import or extend a template, but through the use of helpers you can create a similar result.

We can take advantage of the fact that our body template is processed before the layout template. Knowing this, we can create two helpers block and extend which can be used to 'inject' custom stylesheets or scripts into the layout template. The block helper will act as a placeholder for values specified in earlier extend helpers.

See examples/extend for a working example. Note how the index.hbs file defines extra stylesheets and scripts to be injected into the layout. They are put into the head section and at the end of the body respectively. If this was not done, the stylesheet would be in the body and the script would print foo bar too soon.

Helpful Modules

hbs-utils: A small utility library that provides helpers for registering and compiling partials, including automatic updates when partials are changed.