0

I have a problem with partials in Handlebars.js.

This is my template and a reuseable partial for it:

Handlebars.registerPartial("children", "{{#child}}[{{age}}]{{/child}}");
var children = Handlebars.compile("{{name}} -> {{>children}}");

And here is my first data:

children({
  "name": "Alice",
  "child": [{
    "age": 6
  }, {
    "age": 11
  }]
});

This leads to the expected and correct output:

 Alice -> [6][11]

But when I use the following data with an empty array:

children({
  "name": "Bob",
  "child": []
});

With this data I will get the error message:

Error: You must pass a string or Handlebars AST to Handlebars.compile. You passed function (context, options) {if (!compiled) { compiled = compileInput(); } return compiled.call(this, context, options); }

But I expected the output "Bob ->"...

When I don't use the partial doing like this, everything works fine:

var children = Handlebars.compile("{{name}} -> {{#child}}[{{age}}]{{/child}}");

But I really want to do it with the partial due to reusability. Why can't I give an empty array to this partial?

Thanks!

Laryllan
  • 41
  • 5
  • Works for me http://jsfiddle.net/LPpEQ/, try updating handlebars – megawac Nov 15 '13 at 15:09
  • Thanks for your help. I even have version 1.1.2 (your fiddle is 1.0.9). I now went back to 1.0.12 and now everything works fine for me. Maybe there is bug in 1.1.2?! – Laryllan Nov 15 '13 at 15:17

0 Answers0