E
E
Evgeny Matveev2014-06-27 14:01:05
CoffeeScript
Evgeny Matveev, 2014-06-27 14:01:05

How to force Ember to display a different "layout" for a specific controller (route)?

Task
Display only the main page in one layout (layout), all the rest - in another (the same for all).
Specifically, on the main page, it is necessary to "nail" the footer to the bottom of the browser (window), and on the rest of the pages of the site, it must be "nailed" to the bottom of the site itself.
What I tried I
added a check of the current route to the controller and added if / else to the renderTemplate in the router to display the layout in the form I need. Code below.

App = Ember.Application.create
  currentPath: ''

App.ApplicationController = Ember.Controller.extend
  updateCurrentPath: (->
    App.set('currentPath', @get('currentPath'))
  ).observes('currentPath')

  isIndexPage: (->
    true if @currentPath == 'index'
  ).property()

App.ApplicationRoute = Ember.Route.extend
  renderTemplate: ->
    if @get("controller.isIndexPage")
      @render "window-footer"
    else
      @render "footer"

What else I tried
I made the footer a separate outlet and indicated to each router which footer to insert - it did not work.
I tried various methods from the Ember guides, I did not find a working option :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Matveev, 2014-06-27
@Masaki42

The question seems to have been resolved by itself.
Everything turned out to be simpler than I expected - it took only a separate outle and footer.

// application.emblem
.wrapper
if isIndexPage
  = partial "header"
  .main-content
    = outlet index
  = render index/footer
else
  = partial "header"
  .main-content
    = outlet
  = render footer

// App.IndexRoute
  renderTemplate: ->
    @render
      outlet: 'index'

ps In App.ApplicationController there are methods for determining the current path, if anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question