Fred J.
Fred J.

Reputation: 6029

for each item in array {{display item}}

I am trying to access the array values in my code so that I can use them but I am not sure how to. Thanks

var footerButtons = ['NO', 'EXTRA', 'YES'];

<template name="footer">
  {{#each footerButtons}}
    <h1>
      <button class="col-xs-2 mainMenu" type="button">{{what should go here?}}</button>
    </h1>
  {{/each}}
</template>

Upvotes: 1

Views: 51

Answers (2)

umesh
umesh

Reputation: 338

You could define your footerButtons helper as follows -

Template.footer.helpers({
  footerButtons() {
    return [{text: 'NO'}, {text: 'EXTRA'}, {text: 'YES'}];
  }
});

Then in your template, you can access the values as shown below.

<template name="footer"> 
  {{#each footerButtons}}
    <h1> <button class="col-xs-2 mainMenu" type="button">{{text}}</button> </h1> 
  {{/each}}
</template>

Upvotes: 2

Matt O&#39;Connell
Matt O&#39;Connell

Reputation: 287

{{.}} or {{this}} is what you're looking for. This refers to the current object/element in an array.

Upvotes: 2

Related Questions