I have a Handlebars template which is rendered using a json object. In this json I am sending an array. Like this:
var json = {
"array":["abc","def","ghi","jkl"]
}
Now in my template I want to find the length of this array. Something like:
{{#each item}}
{{ array.length }}
{{/each}}
Couldn't find it in the Handlebars documentation.
If you are testing for an empty list in order to display content... In Ember.js which uses handlebars, you can have an else for the #each.
In this case you need to reference the parent variable of the each from within the each block:
I think your variable being named "array" is probably conflating the issue as well. Let's assume some different JSON just to clarify:
So then doing this:
Would yield:
try this:
You can define simple helper to handle it:
And then use it in your template eg:
My Bad....
{{array.length}}
actually worked inside the template. Should have checked/tested it before posting it here.