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
  • 7,874
  • 4
  • 24
  • 46

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
  • 3,778
  • 1
  • 28
  • 29