1

So I want to be able to do something like this:

"{{tickets." + index + ".comments.0.account}}"

I want to be able to specify the index of the array that I am trying to get data from with a javascript variable. Currently this code gives me an error which says:

Expecting 'ID', got 'STRING'

I am actually using express-handlebars with Node.js if this makes a difference.

Alexander Craggs
  • 6,776
  • 4
  • 20
  • 38

1 Answers1

2

Create a helper:

Handlebars.registerHelper('getTicketAccount', function(context, i) {
  // Error handling ommitted for brevity
  return context[i].comments[0].account;
});

To use:

{{getTicketAccount tickets index}}
datchung
  • 2,490
  • 22
  • 21