Ember.js 如何使用Ember CLI在两个组件之间共享模板?

Ember.js 如何使用Ember CLI在两个组件之间共享模板?,ember.js,ember-cli,Ember.js,Ember Cli,我有两个组件:SpecialButtonComponent和specialbuttonevirativecomponent SpecialButton组件自动使用在/app/templates/components/special button.hbs中找到的模板 我想让SpecialButtonDervativeComponent使用相同的模板,但到目前为止,我还没有机会尝试使用这种技术: // app/components/special-button-derivative.js impor

我有两个组件:
SpecialButtonComponent
specialbuttonevirativecomponent

SpecialButton
组件自动使用在
/app/templates/components/special button.hbs
中找到的模板

我想让
SpecialButtonDervativeComponent
使用相同的模板,但到目前为止,我还没有机会尝试使用这种技术:

// app/components/special-button-derivative.js
import SpecialButtonComponent from './special-button';

export default SpecialButtonComponent.extend({
  templateName: 'components/special-button'
});

我也尝试过使用
layoutName
而不是
templateName
,但仍然没有成功。有什么想法吗?

组件没有
模板名


我会尝试将
layout
设置为null,然后在
Ember 2.2
layoutName
中指定一个
layoutName

成为私有API。我建议使用
Gabriel Grant
解决方案,并设置父组件的
layout
属性

// parent-component
import Component from '@ember/component';
import layout from '../templates/parent-component';

export default Component.extend({
  layout
});


// child-component
import ParentComponent from './parent-component';

export default ParentComponent.extend({
});

layoutName
就可以了。在ember 2.0中,不需要该属性,但您必须确保扩展组件没有创建模板文件。因为如果有模板文件,它将覆盖继承的模板。因此,请确保从v2.12开始删除它的模板:)@farzanmaydani。除非父组件恰好明确设置了它的
layout
属性,否则您的建议实际上似乎并没有按照描述的那样起作用。要在一般情况下执行此操作,需要将子类“
layout
设置为父级模板。有关详细信息,请参阅本期GH: