Iron Router: get the name of the current controller

I know you can get the name of the current route name using Router.current().route.getName()

, but how can I get the name of the controller's current route ?

Here is an example of how I define my controller (s):

Router.configure
    layoutTemplate: 'LayoutFluid'
    yieldRegions:  
        "footer": {to: "footer"}
        "header": {to: "header"}


@QuantifyController = RouteController.extend
    layoutTemplate: "LayoutSidebar"
    yieldRegions:
        "footer": {to: "footer"}    
        "header": {to: "header"} 
        "QuantifyMenu": {to: "sidebar"}
    action: ->
        @render()

Router.map ->
    @route "Home",
        path: "/"
    @route "Blog",
        path: "/blog"
    @route "QuantifyIndex",
        path: "/quantify"
        controller: "QuantifyController"
    @route "QuantifyNewProject",
        path: "/quantify/new"
        controller: "QuantifyController"
    @route "Quantify..." #you get the idea

      

FWIW, the reason I need to get this is for CSS purposes. I add the route name as a css class to the body, which means that when defining common styles for the views using QuantifyController

I need to do body.QuantifyIndex, body.QuantifyNewProject, body.Quantify...

, which means every time I add a new route Quantify..

I need to add it to the css as well, which is just not perfect ... If I can get the name of the controller, I can just use body.QuantifyController {...}

in CSS, which is much more ideal.

+3


source to share


1 answer


Got! After hours of searching, I found that it is defined at:

Router.current().route.options.controller

...



Note that if the current controller is the default controller ( RouteController

) you will get undefined

.

@SG_ your comment helped me get there. Thanks again.

+3


source







All Articles