spullen
spullen

Reputation: 3317

does emberjs have an equivalent to rails `yield :something`?

In rails you can do things like:

application.html.erb:

<h1><%= yield :title %></h1>
<%= yield %>

someother_template.html.erb:

content_for :title { 'Some Title' }

other stuffz

Is there a way to do this sort of thing using emberjs?

Upvotes: 2

Views: 562

Answers (1)

Mike Grassotti
Mike Grassotti

Reputation: 19050

Is there a way to do this sort of thing using emberjs?

If you want yield-as-in-layouts then yes, you can use the handlebars {{yield}} helper to wrap a view

AViewWithLayout = Ember.View.extend({
  layout: Ember.Handlebars.compile("<div class='my-decorative-class'>{{yield}}</div>")
  template: Ember.Handlebars.compile("I got wrapped"),
});

See Ember.Handlebars.helpers#yield

If instead you want yield-as-in-content-for, there is not a direct parallel AFAIK. Not sure the content-for pattern really makes sense in the context of handlebars templates, since content_for is about making an assignment from within a template. The preferred way in ember to set something like {{title}} in your application template is binding it to a property of the application controller.

Upvotes: 2

Related Questions