shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.

Home Page:http://npm.im/gulp-hb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing the data from helper to partial

letstestcode opened this issue · comments

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? */));
    });
};

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: