Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Last active February 3, 2018 05:56
Show Gist options
  • Save jonschlinkert/b2691da836a4c1158f4e to your computer and use it in GitHub Desktop.
Save jonschlinkert/b2691da836a4c1158f4e to your computer and use it in GitHub Desktop.
A helper that adds variables from the options hash to the `@` namespace (like `@root`).
Handlebars.registerHelper('foo', function (name, context, options) {
var fn = Handlebars.compile(Handlebars.partials[name]);
var frame = Handlebars.createFrame(context.data);
for (var prop in options.hash) {
frame[prop] = options.hash[prop];
}
var template = fn(context, {data: frame});
return new Handlebars.SafeString(template);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment