diff --git a/lib/handlebars.js b/lib/handlebars.js index 73a035d9..a1efa288 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -107,6 +107,8 @@ Handlebars.Compiler.prototype = { break; case ".": // do nothing - using .'s is pretty dumb, but it's also basically free for us to support + case "this": + // if we do nothing you'll end up sticking in the same context break; default: readDepth = true; diff --git a/test/handlebars.js b/test/handlebars.js index f3620f79..15c231c6 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -47,6 +47,16 @@ test("bad idea nested paths", function() { shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths"); }); +test("this keyword in paths", function() { + var string = "{{#goodbyes}}{{this}}{{/goodbyes}}"; + var hash = {goodbyes: ["goodbye", "Goodbye", "GOODBYE"]}; + shouldCompileTo(string, hash, "goodbyeGoodbyeGOODBYE", + "This keyword in paths evaluates to current context"); + + string = "{{#hellos}}{{this/text}}{{/hellos}}" + hash = {hellos: [{text: "hello"}, {text: "Hello"}, {text: "HELLO"}]}; + shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths"); +}); module("blocks");