bigt11
bigt11

Reputation: 78

handlebars #each array is helper

I have a helper that returns requested array. I want to use an each to iterate the array returned by the helper. Any way to get this to work?

imagine the handlebars helper returns this array

names: [{
     firstname: "first1",
     lastname: "last1"
},{
     firstname: "first2",
     lastname: "last2"
}]

My handlebars code would looks something like this

{{#each myhelpername "keyword passed to helper"}}
<p>Hi {{firstname}} {{lastname}}</p>
{{/each}}

Upvotes: 1

Views: 411

Answers (1)

Sushanth --
Sushanth --

Reputation: 55750

If your helper is already returning an array why do you need to use #each again.

The firstName and lastName should be part of each item which is returned. So your template would look something in these lines.

{{#myhelpername "keyword passed to helper"}}
    <p>Hi {{firstname}} {{lastname}}</p>
{{/each}}

If you need to iterate over the helper using an each wrap it inside ()

{{#each (myhelpername "something something")}} 
    <p>Hi {{firstname}} {{lastname}}</p>
 {{/each}}

Upvotes: 0

Related Questions