Help with application.handlebars and its data model


#1

Hi,

How can I get a model into my application.handlebars? All the examples I’ve seen for application.handlebars have no data, and for the life of me, I cannot sort out how to set-up the application_route.js / application_controller.js such that it can push a model into application.handlebars.

Thanks!


#2

For any route, including ApplicationRoute, whatever you return from the route’s model hook is what will eventually be loaded into the controller for that route, and therefore accessible by the handlebars template.

So if you had

App.ApplicationRoute = Ember.Route.extend({
  model: function() {
    return { foo: 5 };
  }
}

You could do something like this for application.handlebars:

foo is {{foo}}
{{outlet}}

The outlet is so that any nested route content (IndexRoute or whatever the current url refers to) also gets rendered.