Closed
Description
Hey there, I'm having trouble with one aspect of using handlebars in a node setting.
When I want to share helpers from various places, and I want to use handlebars.SafeString
, I am finding it difficult, since the instanceof
check will only pass if the SafeString
object came from the local instance. With node, there could be several versions of handlebars installed, but only the local one passes.
Passing around a single instance of handlebars to all of these modules is not ideal, especially for such a trivial thing. I have a few proposals (in order of preference/ease-of-implementation)
- add
SafeString
to the context of the helper, so I don't need any other external reference for it to work:
exports.myHelper = function (options) {
return new options.SafeString("foo");
};
- use duck-typing within
Utils.escapeExpression
, rather than (or in addition to)instanceof
:
} else if (typeof string === "object" && typeof string.string === "string") {
// this test may not be accurate, this is just an example
}
- execute helpers using the handlebars instance as
this
exports.myHelper = function () {
return new this.SafeString("foo");
};
For now, I can just use {{{
to accomplish what I need. So, this is not "urgent", but I would like to start the discussion. :)