Closed ricardograca closed 9 years ago
There are two options to gain access to Handlebars:
1) Depend on the handlebars
package in your app, and pass a ref along to Express Handlebars using the handlebars
config option
2) Create an Express Handlebars instance, then access Handlebars via the handlebars
prop.
Using either of these approaches will give you access to the Handlebars
object on which you can call registerHelper()
to add a global helper.
Thanks for your answer. What about the issue of the documentation being incomplete? Do you want me to create a pull-request to fix that?
@ricardograca Yeah that would be great, thanks!
The documentation about helpers says that:
But in reality it only shows examples of helpers being defined on instance and render levels.
I know I can use the
registerHelper
method of Handlebars, however express-handlebars doesn't seem to have anyregisterHelper
methods on the object returned byrequire('express-handlebars')
. After looking in the source code it seems the Handlebars object is available atExpressHandlebars.prototype.handlebars
, so is the only way to register a global helper something like this: