Getting current route name from template in Symfony

Posted on Category:PHP, MySQL

When creating webpages with navigation and menus, it is often nessesary to assign css class for menu item that the visitor is currently viewing. This post shows an example how to get current route name from a template for that purpose.
Route name of currently running module/action can be accessed from template like in a following example:
[php]$route = $sf_context->getInstance()->getRouting()->getCurrentRouteName();
Also, current route name can be accessed from anywhere by:
$route = sfContext::getInstance()->getRouting()->getCurrentRouteName();