Search code examples
ember.jsember-cli

EmberJS - Using a custom layout/template instead of applcation.hbs


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

  # ...

Solution

  • 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'
    });