在rails中可以这样做:
application.html.erb:
<h1><%= yield :title %></h1>
<%= yield %>
someother_template.html.erb:
content_for :title { 'Some Title' }
other stuffz
是否有一种方法可以使用emberjs来做这种事情?
是否有一种方法可以使用emberjs来做这种事情?
如果你想要yield-as-in-layouts,那么是的,你可以使用handlebars {{yield}}
helper来包装视图
AViewWithLayout = Ember.View.extend({
layout: Ember.Handlebars.compile("<div class='my-decorative-class'>{{yield}}</div>")
template: Ember.Handlebars.compile("I got wrapped"),
});
看到Ember.Handlebars.helpers #收益率
如果您想要yield-as-in-content-for,则没有直接的并行AFAIK。不确定content-for模式在句柄模板的上下文中是否真的有意义,因为content_for是关于在模板内进行赋值的。在ember中,在应用程序模板中设置{{title}}之类的东西的首选方法是将其绑定到应用程序控制器的属性。