{{if }} conditional statement errors
-
i am looping thru a json data object and doing a if conditional statement like this
{{#each results}}
{{#if checkraceid raceID == true}}
<h3>true</h3>
{{else}}
<h4>false</h4>
{{/if}}
{{/each}}
i have a function called checkraceid like this:
function checkraceid (id) {
console.log(id);
if (id != myraceid) {
myraceid = id;
return false;
}
return true;
}
why does it always error on the {{#if}} statement?
keeps showing this error: Parse error on line 10: ...checkraceid raceID == true}} -----------------------^ Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EQUALS' logsi even tried using {{if }} by removing the # but still error
what is the correct way to do a conditional statement like that?
-
I am afraid handlebars
if
helper doesn't support passing a custom condition likeraceID == true
.
You should pass a single variable or make your ownif
helper if you need something more complicated.
-
thank you
thats the conclusion i came up with and have gone a different route to customize my json data structure in my web api
-
In the documentation of version 2.8 I found this example
{{#if (moreThan2 users)}}More than 2 users
{{ else }} Less or equal to 2 users
{{/if}}You can try
{{#if (checkraceid raceID)}}No spaces between {{#if
Hope this helps someone using old versions.