Skip to content

Commit

Permalink
Add append for block-for
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko committed Mar 11, 2016
1 parent b18cc94 commit 05bb4fe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ And can be used like so:

Which allows using `concat` or other helpers to dynamically set the name.

### Appending

By default if you call a `block-for` multiple times, it overwrites the previous content. Sometimes
you might want to append to the previous content.

```hbs
{{#yields.header append=true}}
A
{{/yields.header}}
{{#yields.header append=true}}
B
{{/yields.header}}
```

Now the header will have 'AB' as it's contents.


## Contribute

Expand Down
3 changes: 3 additions & 0 deletions addon/components/block-for/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import Ember from 'ember';
import layout from './template';
import PortalContent from 'ember-portal/components/portal-content';

const { computed } = Ember;

const Component = PortalContent.extend({
layout: layout,
tagName: '',
append: computed.alias('showingPortalItem'),

didReceiveAttrs() {
var id = this.get('prettyId');
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/app/application/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Ember from 'ember';

export default Ember.Controller.extend({
items: ['a', 'b', 'c']
});
9 changes: 6 additions & 3 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
{{#yields.named 'footer'}}
Footer
{{/yields.named}}
{{#yields.header as |args|}}
{{args.name}}
{{/yields.header}}

{{#each items as |item|}}
{{#yields.header append=true as |args|}}
{{args.name}} {{item}}
{{/yields.header}}
{{/each}}
Me
{{/my-card}}

0 comments on commit 05bb4fe

Please sign in to comment.