opsb
opsb

Reputation: 30211

Access parent context from ember component block

I'm trying to work out how blocks work with ember components. With the following I'd expect project.name to be rendered for each loop.

// components/block-test.js
export default Ember.Component.extend({});

// index.hbs
{{#each project in projects}}
    {{#block-test}}
        {{project.name}}
    {{/block-test}}
{{/each}}

But when I use this pattern project.name is not rendered. Is this the expected behaviour and if so how could I change it to get the above code to work?

Upvotes: 4

Views: 1680

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

component's are intentionally isolated, pass in anything you want to use (you don't need yield if you are passing it in)

{{#block-test project=project}}
    --{{project.name}}--
{{/block-test}}

No Component template

 --apple--
 --dog--
 --piano--

With yield

Component template

--{{yield}}--

Using Component

{{#block-test}}
    {{project.name}}
{{/block-test}}


 --apple--
 --dog--
 --piano--

Upvotes: 4

Related Questions