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.

1
  • You don't show enough code. Commented May 23, 2015 at 12:48

1 Answer 1

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}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.