diff --git a/lib/template.js b/lib/template.js index 14f396d..373ba59 100644 --- a/lib/template.js +++ b/lib/template.js @@ -141,7 +141,7 @@ var Hogan = {}; doModelGet = this.options.modelGet, cx = null; - if (key === '.' && isArray(ctx[ctx.length - 2])) { + if (key === '.' && (ctx.length === 1 || isArray(ctx[ctx.length - 2]))) { val = ctx[ctx.length - 1]; } else { for (var i = 1; i < names.length; i++) { diff --git a/test/index.js b/test/index.js index ec0777e..82c2e6f 100644 --- a/test/index.js +++ b/test/index.js @@ -691,6 +691,13 @@ test("Implicit Iterator", function() { is(s, " 42 43 44 ", "implicit iterators work"); }); +test("Root-level Implicit Iterator", function() { + var text = '{{#.}} {{name}} {{/.}}'; + var t = Hogan.compile(text); + var s = t.render([{name:"a"},{name:"b"}]); + is(s, " a b ", "root-level implicit iterators work"); +}); + test("Partials And Delimiters", function() { var text = '{{>include}}*\n{{= | | =}}\n*|>include|'; var partialText = ' .{{value}}. ';