diff --git a/lib/handlebars/compiler.js b/lib/handlebars/compiler.js index 655dcd3a..782c854a 100644 --- a/lib/handlebars/compiler.js +++ b/lib/handlebars/compiler.js @@ -99,6 +99,10 @@ Handlebars.registerHelper('if', function(context, fn, inverse) { } }); +Handlebars.registerHelper('with', function(context, fn) { + return fn(context); +}); + Handlebars.logger = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3, diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index c63edb01..44b5ea4b 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -486,4 +486,12 @@ test("if a context is not found, helperMissing is used", function() { var context = { hello: "Hello", world: "world" }; shouldCompileTo(string, context, "Hello world") -}) +}); + +module("built-in helpers"); + +test("with", function() { + var string = "{{#with person}}{{first}} {{last}}{{/with}}"; + + shouldCompileTo(string, {person: {first: "Alan", last: "Johnson"}}, "Alan Johnson"); +});