Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple yields #43

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions active/0000-multiple-yields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
- Start Date: 2015-04-01
- RFC PR: (leave this empty)
- Ember Issue: (leave this empty)

# Summary

Allow templates to have multiple `{{yield}}`'s.

# Motivation

Today components and layouts are limited to a single `{{yield}}` which makes it difficult to deal with even slightly complex layouts and components.

# Detailed design

```hbs
{{!-- templates/components/my-component --}}
<div class="my-component">
<div class="my-component-body">
{{yield}}
</div>

{{#has-content-for "footer"}}
<div class="my-component-footer">
{{yield content-for="footer"}}
</div>
{{/has-content-for}}
</div>
```

```hbs
{{!-- templates/index.hbs --}}
{{#my-component}}
<p>Here is some body text</p>

{{#content-for "footer"}}
<p>Here is some footer text</p>
{{/content-for}}
{{/my-component}}
```

```html
<!-- Rendered Output -->
<div class="my-component">
<div class="my-component-body">
<p>Here is some body text</p>
</div>

<div class="my-component-footer">
<p>Here is some footer text</p>
</div>
</div>
```

# Drawbacks

N/A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when composing multiple components, naming collisions become quite possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of multiple layers of components?

{{#my-component}}
  {{#content-for "body"}}
    {{#other-component}}
      {{#content-for "body"}}
        Hello
      {{/content-for}}
    {{/other-component}}
  {{/content-for}}
{{/my-component}}

I see no reason why these wouldn't be localized to the current context they are in. Can you give an example of when this would be a problem?


# Alternatives

@stefanpenner mentioned some ideas he had, I'll let him explain them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yielded components/helpers from the component could help disambiguate ^^

a quick related example: https://gist.github.com/stefanpenner/86812ac262414232285c


# Unresolved questions

N/A