patrickkettner/grunt-compile-handlebars

Need to access handlebars instance so I can get the partials.

Closed this issue · 5 comments

Hi,

I'm making a helper to dynamically change the partial, something like this:
var handlebars = require('../../../../node_modules/grunt-compile-handlebars/node_modules/handlebars/dist/handlebars.min.js');
module.exports = function (name) {
var partial = handlebars.partials[name];
// Return empty string if the partial is not defined
if (!partial) return "";
// Compile and call the partial with this as context
return new handlebars.SafeString(handlebars.compile(partial)(this));
};

Problem is that handlebars.partials is empty since this is not the same instance as the one where the partials were stored.

Regards,

Johnny

Hiya @dzjcr

You can actually supply your own instance of handlebars in the config (the handlebars param). That should take care of it, no?

if I do that how do I reference handlebars on the helper?

reference the same file in your helper (that is, the path to the same file).

Thanks,

That made the trick

:)

my pleasure!