Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Array length inside the Handlebar templates?

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.

like image 549
Abhidev Avatar asked Mar 15 '13 09:03

Abhidev


People also ask

How do I measure my handlebar length?

All you'll need is a tape measure to take an accurate measurement. Place and hold one end of the tape measure on the end of your mountain bike handlebars. Pull the tape along the handlebar towards the other end and take the reading where the handlebar finishes in mm. This measurement is the handlebar width.

How do you compare two values in handlebars?

How can I compare the predefined values to the original value from JSON so that it can execute properly? Handlebars. registerHelper('if', function (variable_from_json, options) { if (variable_from_json === "M") { return options. fn(this); } else { return options.


1 Answers

My Bad....

{{array.length}} actually worked inside the template. Should have checked/tested it before posting it here.

like image 137
Abhidev Avatar answered Sep 24 '22 19:09

Abhidev