Multiple layouts in Ember 2


#1

I need implement next application structure with 3 routes:

localhost/users
localhost/posts
localhost/settings

‘users’ and ‘posts’ routes should have basic layout1 with main navbar. ‘settings’ route should have another layout2 with second navbar.

How can I implement multiple layouts approach with Ember > 2.12? Can I set a layout name/path for each route or group of routes?


#2

Hey @okachynskyy,

By “layout” do you mean just CSS or markup as well? If it’s just CSS I’d use a property on the routes that you want with layout1/layout2 and set CSS classes or something accordingly.

If there’s it’s a markup difference you’d probably want to either:

  1. Make a parent route for layout1 and one for layout2 and put the layout markup in those respective parent routes
  2. Or have a property on the application controller that returns either layout1 or layout2 depending on what child route you’re at, and then the application template can determine which layout to render with a simple #if block