diff --git a/README.md b/README.md index 4785d02..005cc37 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/addon/components/block-for/component.js b/addon/components/block-for/component.js index 1f55734..e1c8968 100644 --- a/addon/components/block-for/component.js +++ b/addon/components/block-for/component.js @@ -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'); diff --git a/tests/dummy/app/application/controller.js b/tests/dummy/app/application/controller.js new file mode 100644 index 0000000..df7269d --- /dev/null +++ b/tests/dummy/app/application/controller.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + items: ['a', 'b', 'c'] +}); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index d080f43..153450f 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -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}} \ No newline at end of file