Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created September 20, 2018 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ppcano/5141222076cbc62c4eab8493c71a65fb to your computer and use it in GitHub Desktop.
Save ppcano/5141222076cbc62c4eab8493c71a65fb to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember - Workaround to yield multiple blocks'
});
<h1>Ember - Workaround to yield multiple blocks</h1>
The <a href="https://github.com/emberjs/rfcs/blob/master/text/0226-named-blocks.md">Named Templates Block API</a> will add the ability to pass multiple blocks to a component.
<br><br>
Meanwhile, a possible workaround could be to split your component into multiple subcomponents and allow to set the subcomponent block by passing them as block parameters.
<br><br>
{{my-component}}
<br><br>
{{#my-component as |f|}}
{{f.header}}
{{#f.content}}
Custom content
{{/f.content}}
{{f.footer}}
{{/my-component}}
<br><br>
{{#my-component as |f|}}
{{#f.header}}
Custom header
{{/f.header}}
{{#f.content}}
Custom content
{{/f.content}}
{{#f.footer}}
Custom footer
{{/f.footer}}
{{/my-component}}
<div class="container">
{{yield (hash
header = (component 'my-header')
content = (component 'my-content')
footer = (component 'my-footer')
)}}
{{#unless hasBlock}}
{{my-header}}
{{my-content}}
{{my-footer}}
{{/unless}}
</div>
{{#if hasBlock}}
{{yield}}
{{else}}
Default content
{{/if}}
{{#if hasBlock}}
{{yield}}
{{else}}
Default header
{{/if}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment