v1.0.0 Breaking Changes

The file extension for partial files must now match the extension configured in extname - please see the PR

Usage

To use with express 4.

varhbs=require('express-hbs');// Use `.hbs` for extensions and find partials in `views/partials`.app.engine('hbs',hbs.express4({partialsDir: __dirname+'/views/partials'}));app.set('view engine','hbs');app.set('views',__dirname+'/views');

If path starts with '.'
layout is relative to template
Else If `layoutsDir` is set
layout is relative to `layoutsDir`
Else
layout from path.resolve(viewsDir, layout)

Lastly, use defaultLayout if specified in hbs configuration options.

Layouts can be nested: just include a declarative layout tag within any layout
template to have its content included in the declared "parent" layout. Be
aware that too much nesting can impact performances, and stay away from
infinite loops!

Engine Instances

Template options

The main use case for template options is setting the handlebars "data" object - this creates global template variables accessible with an @ prefix.

Template options can be set in 3 ways. When setting global template options they can be passed as config on creation of an instance, and they can also be updated used the updateTemplateOptions(templateOptions) method of an instance. To set template options for an individual request they can be set on res.locals using the helper method updateLocalTemplateOptions(locals, templateOptions).

Both of these methods have a companion method getTemplateOptions() and getLocalTemplateOptions(locals), which should be used when extending or merging the current options.