Skip to content

Instantly share code, notes, and snippets.

@dhindurthy
Last active December 5, 2017 22:32
Show Gist options
  • Save dhindurthy/a7593c3b59a92a6241dc104d45cd39bc to your computer and use it in GitHub Desktop.
Save dhindurthy/a7593c3b59a92a6241dc104d45cd39bc to your computer and use it in GitHub Desktop.
ember-wrapped-template
import Ember from 'ember';
export default Ember.Component.extend({
classNames:['component-one']
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames:['component-two'],
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Wrapped Template'
});
import Ember from 'ember';
export default Ember.Controller.extend({
title: 'Wrap Share',
author: 'Some Person',
abc:'Data-From-Component-One',
valueOfTwo:'valueTwo of component-two assigned through controller in index'
});
import Ember from 'ember';
export default Ember.Route.extend({
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.component-two {
color: brown;
}
.component-one {
color: blue;
}
<h3 style="color:orange">Start of application template - Contextual Component</h3>
{{outlet}}
<h3 style="color:orange">End of application template</h3>
<h3>Start of component-one template</h3>
<h4>Title added as part of component-one: {{title}}</h4>
<hr>
<div class="body">
{{yield
(hash
otherComponentsBody=(component nameOtherComponent dataOfTwo=dataOfOne)
)
}}
</div>
<hr>
<p>Data that belongs to component-one: <u>{{dataOfOne}}</u></p>
<h3>End of component-one template</h3>
<h3>Start of component-two template</h3>
{{yield}}
<p> Property of component-two which is "binded TO a property of component-one" in component/hash helper(in component-one's template) is displayed here </p>
<u><i>{{dataOfTwo}}</i></u><br>
<u><i>{{labelTwo}}</i></u><br>
<u><i>{{valueTwo}}</i></u>
<p><u>Note form two</u>: This above underlined data belongs to component-two but because of the "binding" and coontextual components, we are able to access it via component-one as well</p>
<h3>End of component-two template</h3>
<h3 style="color:violet">Start of index template</h3>
{{#component-one title=title nameOtherComponent="component-two" dataOfOne=abc as |something|}}
<p style="color:violet">Author added in index template inside the component-one block template: {{author}}</p>
{{something.otherComponentsBody labelTwo='labelTwo assigned in index' valueTwo=valueOfTwo}}
{{/component-one}}
<h3 style="color:violet">End of index template</h3>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment