Guilherme Aiolfi
Guilherme Aiolfi

Reputation: 45

How to use inner template of Em.ContainerView as child's template

I created a ListView and I want to be able to do this:

{{#view UI.ListView}}
     <div class="icon"><img src="{{icon}}" /></div>
     <span class="name">{{name}}</span>
{{/view}}

and use the:

<div class="icon"><img src="{{icon}}" /></div>
<span class="name">{{name}}</span>

as the childView template.

How do I do that?

EDIT: Maybe I wasn't clear enough in my question. Here is what I ended up with: https://gist.github.com/1626943 (See lines 27-30). I was trying to get the inner template string of the the view but that's not available anywhere (at least I couldn't find it). There is only the compiled version available. But that's seems to be enough.

Upvotes: 0

Views: 244

Answers (2)

Tom Whatmore
Tom Whatmore

Reputation: 1327

  1. Just wanted to point out you should be using the bindAttr helper for the image src.

  2. I don't think Dan's answer will work, as it's binding each item to entry, but then using item.name in the child view.

I've put together a JS Fiddle to show both these things: http://jsfiddle.net/tomwhatmore/xXq7e/1/

Upvotes: 1

Dan Rabinowitz
Dan Rabinowitz

Reputation: 99

list.handlebars should look like this:

{{#each items}}
{{view App.ShowItemView entryBinding="this"}}
{{/each}}

And, show.handlebars should look like ths:

<div class="icon"><img src="{{icon}}" /></div>
<span class="name">{{item.name}}</span>

Upvotes: 0

Related Questions