stackers
stackers

Reputation: 3279

How can you get a dynamically named variable in handlebars?

I am trying to output a table using handlebars.

Right now it loops through the each row, and then through each column, but how can I grab the data from the row based on {{col.name}}?

See here, I need to get COLUMNNAME from {{col.name}}

{{#rows as |row|}}
  <tr>
    {{#../cols as |col|}}
      <td>{{row.COLUMNNAME}}</td>
    {{/../cols}}
  </tr>
{{/rows}}

In js this would be like row[index][col.name];

Any idea for solutions?

Upvotes: 1

Views: 1396

Answers (1)

stackers
stackers

Reputation: 3279

Found the answer, it's the lookup tag.

{{lookup row col.name}}

is equal to

row[col.name]

Upvotes: 1

Related Questions