shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
148 stars 14 forks source link

Passing the data from helper to partial #65

Closed letstestcode closed 6 years ago

letstestcode commented 6 years ago

Hello.

Thanks the author for the nice extension)

I have a question.

I have a helper that have to run a partial. Data in this partial must be the same as in the template where helper was called. How to pass the data correctly from the helper to the partial.

There is the code of the helper.

module.exports.register = function (handlebars) {
    handlebars.registerHelper('runhelper', function (context) {
        var partial = handlebars.partials['partialName'];

        if (typeof partial !== 'function') {
            partial = handlebars.compile(partial);
        }

        return new handlebars.SafeString(partial(/* what's the data here? */));
    });
};
shannonmoeller commented 6 years ago

Thank you for your kind words.

As to your question, it depends. Handlebars has a concept of global data, but there's also local data that you pass directly to the helper when you use it in a template.

See: