yuяi
yuяi

Reputation: 2715

How to get current Ember app route from template

I'm trying to set element class attributes based on current route. This is inside a navigation handlebars partial included in the Application handlebars template.

In my ApplicationController I can do something like:

isUsers: ( ->
  @get('currentPath') == 'users.index'
).property('currentPath')

In the navigation template I want to do something like:

<a {{bind-attr class="isUsers:active:inactive"}} href="users"></a>

This doesn't work - inactive class is always set, even when in correct app path.

Any suggestions?

Upvotes: 1

Views: 1097

Answers (1)

Gautham
Gautham

Reputation: 3538

If you are defining the isUsers property in the ApplicationController, then are you sure you are using it in the application.handlebars or whatever template used by the ApplicationController? If you are using in a template which has a different Controller, make sure you use the following in your controller.

App.MyController = App.Controller.extend
  needs: ['application']

In the template,

controllers.application.isUsers

Upvotes: 2

Related Questions