Skip to content

Instantly share code, notes, and snippets.

@HenryVonfire
Last active November 16, 2015 09:50
Show Gist options
  • Save HenryVonfire/285dca9ef416ae1ea482 to your computer and use it in GitHub Desktop.
Save HenryVonfire/285dca9ef416ae1ea482 to your computer and use it in GitHub Desktop.
Sharing templates between components
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Sharing templates between components'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<p>There are 2 components, the first one with a template and the second one without it. Rendering the second-component we obtain this:</p>
{{second-component}}
<br>
<br>
import Ember from 'ember';
export default Ember.Component.extend({
});
<h4>this is component first</h4>
import Ember from 'ember';
import layout from '../first-component/template';
export default Ember.Component.extend({
layout: Ember.computed(function() {
//One way is by importing the template and the
//other way is by using templateForName
return layout;
//return this.templateForName('first-component')
})
});
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment