0

In my Ember template in my application, I have got a header tag, which should print the title of the current route. Does anyone know how I would accomplish this in EmberJS? Is there any way to set a variable once a route is accessed?

Roman Melnyk
  • 1,097
  • 1
  • 8
  • 21
WebDevDude
  • 829
  • 1
  • 8
  • 14

3 Answers3

1

Route

Ember.Route.extend({
  setupController: function(controller) {
    controller.set('routeName', this.routeName);
  }
});

Controller

Ember.Controller.extend({
  routeName: null
});

Template

<header>{{routeName}}</header>
Miguel Mota
  • 20,135
  • 5
  • 45
  • 64
1

If you about application template, there is currentPath property in Application Controller (and in some other objects too, see details here: https://github.com/emberjs/ember.js/pull/12034

//application template
<header>{{currentPath}}</header>
artych
  • 3,669
  • 1
  • 17
  • 30
0

There are a few ways.

First, an application controller has a property, currentPath. In this and this answers you may see examples of using it.

Also, you may use didTransition to determine when ember made a transition and update a title in some way.

And finally, if you want to change a document title (displayed in browser tab), there is an addon

Community
  • 1
  • 1
Gennady Dogaev
  • 5,902
  • 1
  • 15
  • 23