0

My if else statements using the "^" for "false" or "not" used to work in both Handlebars 1.3.0 and Mustache.php. When I try the ^ for "if not" in Handlebars 2.0.0 it always disregards that block, no matter if true or false?

{{#repo}}
  <b>{{name}}</b>
{{/repo}}
{{^repo}}
  No repos :({
{{/repo}}
MrRay
  • 1
  • I was wrong. The problem was caused by replacing compiling hbs files with grunt-handlebars-compiler to grunt-contrib-handlebars, and needing the processName option as explained here http://stackoverflow.com/questions/27564868/handlebars-precompile-type-error – MrRay Feb 11 '15 at 10:34

1 Answers1

0

Well those are not simples if/else statements, those ^ inside the {{}} are called inverted sections

An inverted section begins with a caret (hat) and ends with a slash. That is {{^person}} begins a "person" inverted section while {{/person}} ends it.

While sections can be used to render text one or more times based on the value of the key, inverted sections may render text once based on the inverse value of the key. That is, they will be rendered if the key doesn't exist, is false, or is an empty list.

And there is not compatibility issues using mustache with handlebars 2.0, make sure the hash look like this.

{
  "repo": [] //or :false //or well it dosnt exists
}

Also you may wanna take a look into this proposal to change some features of mustache

Ethaan
  • 11,291
  • 5
  • 35
  • 45