views:

52

answers:

1

Hi all,

I'm building a Pylons application using evoque as our templating engine, though I think my question is relevant to other template engines. I have a base template that I'm using for our pages, and that base template does all the includes for CSS and Javascript files. I'd like to perform conditional test to include/exclude CSS and Javascript files based on the actual page being display. Is there a way to access the routes information from the template, in other words to get the /{controller}/{action} information? This would allow me to get only the relevant CSS and Javascript files for that page based on the controller/action combination.

Thanks in advance,

Doug

+2  A: 

You can pull the controller and action information from environ['pylons.routes_dict']['controller'] and ['action'].

I'm not sure if environ is passed into the tmpl_context by default, but if not, you can just add something like this to the BaseController._before_ method:

c.routes_dict = environ['pylons.routes_dict']

Then reference c.routes_dict['controller'] in your template.

Travis