Hi, I’m a beginner to Ember.js and I’m writing an application in which I have a Post model that has a field called extended. I want to loop through each of the Posts and check if its extended field contains a String (say “hi”). I tried this:
But I get this error: Uncaught Error: Parse error on line 10:
… {{#if extended.indexOf(“hi”) != 0}}
----------------------^
Expecting ‘ID’, got ‘INVALID’
You can’t check like this in handlebars if block, you can check against true or false.
You can use the if helper to conditionally render a block. If its argument returns false, undefined, null, “” or (a “falsy” value), Handlebars will not render the block.
So, you have to keep a computed property in your Post model, which returns true or false based on the condition, and check against that in the handlebars
Handlebars are logic-less templates where these sort of checks cannot be done. I suggest you to look through http://handlebarsjs.com/ …
Alternatively, you can also specify itemController for your model in the each helper and handle these sort of logic there