1

As a Rails developer who started messing around with EmberJS one week ago, I want to know if it's possible to use custom layout instead of the provided applictaion.hbs? Like we do it in rails:

class MyController < ApplicationController
  layout :resolve_layout

  # ...
GJK
  • 37,023
  • 8
  • 55
  • 74
Hendry I.
  • 21
  • 4
  • you might find this very useful in order to have a better understanding of the order in which hooks are executed (and what hooks you have available): https://alexspeller.com/ember-diagonal/ – Victor Nițu Mar 31 '15 at 22:28
  • @VictorNitu it is indeed very useful. Thanks Victor. – Hendry I. Apr 01 '15 at 11:45

1 Answers1

1

Indeed you can, but you have to override it in the view, not the controller. You're looking for the templateName property that will allow you to override the default template. You might also want to look at the layoutName property, since it's closely related. (You can read about the difference here.)

App.ApplicationView = Ember.View.extend({
    templateName: 'something_other_than_application'
});

Or if you're using Ember CLI:

// app/views/application.js
export default Ember.View.extend({
    templateName: 'something_other_than_application'
});
GJK
  • 37,023
  • 8
  • 55
  • 74
  • 1
    Also, if you want to be more fancy, and render different templates into different outlets, or render multiple non-default templates you can find more info here: http://guides.emberjs.com/v1.10.0/routing/rendering-a-template/ – Kori John Roys Mar 31 '15 at 09:32
  • Thanks a lot Kori, I will give it a try tonight. – Hendry I. Apr 01 '15 at 11:37
  • @GJK Thanks for Your answer. But overriding the "app/views/application.js" will replace the original "application.hbs". What I want to have is just define custom template for specific view. Thanks in advance, Hendry I. – Hendry I. Apr 01 '15 at 13:04
  • You don't have to override the application view, that was just an example. You can override _any_ view and change the default template. – GJK Apr 01 '15 at 14:07
  • @GJK Thanks a lot, I'm gonna give a try. – Hendry I. Apr 01 '15 at 14:42