How do I access an access array item by index in handlebars?

lukemh picture lukemh · Nov 8, 2011 · Viewed 184.6k times · Source

I am trying to specify the index of an item in an array within a handlebars template:

{
  people: [
    {"name":"Yehuda Katz"},
    {"name":"Luke"},
    {"name":"Naomi"}
  ]
}

using this:

<ul id="luke_should_be_here">
{{people[1].name}}
</ul>

If the above is not possible, how would I write a helper that could access a spefic item within the array?

Answer

dhorrigan picture dhorrigan · Nov 8, 2011

Try this:

<ul id="luke_should_be_here">
{{people.1.name}}
</ul>