Rick
Rick

Reputation: 13

Hash tag links in #each loop with Handlebars and Ember

I have an array of objects:

objects = [
    {
        name: "a",
        val: 1
    }, 
    {
        name: "b", 
        val: 2
    }
]

I'm trying to produce the following HTML with Handlebars:

<ul>
    <li> <a href="#a">...</a> </li>
    <li> <a href="#b">...</a> </li>
</ul>

If I didn't need the hash, I would do it like this:

<ul>
    {{#objects}}
        <li> <a {{bindAttr href="name"}}>...</a> </li>
    {{/objects}}
</ul>

I can't use href="#name" or href=#"name". Is there a way to get the hash in front of the name property?

Upvotes: 1

Views: 486

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

<ul>
    {{#each item in objects}}
        <li> <a href="#{{unbound item.name}}">...</a> </li>
    {{/each}}
</ul>

But i'm not sure what you're doing, you probably want to use the link-to helper

Upvotes: 1

Related Questions