iHiD
iHiD

Reputation: 2438

Rendering a partial multiple times in Ember

I'm trying to render a view in a template multiple times with different data each time, specifically like this:

<script type="text/x-handlebars" data-template-name="foobar">
    {{render "_people" peopleArray}}
    <!-- ... -->
    {{render "_people" anotherPeopleArray}}
</script>

<script type="text/x-handlebars" data-template-name="_people">
    {{#each person in controller}}
       {{person.name}}
    {{/each}}
</script>

I get the JS error: "assertion failed: This view is already rendered".

If I change the {{render "_people"}} to {{partial "people"}} then it will render multiple times, but I do not know how to pass different data into there.

To clarify, I to be able to create a partial/view, which I can pass data to, and can call multiple times. I'm sure this is simple and I'm just missing something.

Any help would be appreciated. Thank you.

Upvotes: 4

Views: 1613

Answers (1)

Jakub Arnold
Jakub Arnold

Reputation: 87210

You can use {{render}} only once. If you need to do it multiple times, use {{control}} instead, such as:

{{control "people" peopleArray}}

This will create a people template with PeopleView and PeopleController with it's content set to peopleArray

Upvotes: 3

Related Questions