What you seek will be "impossible" until Symfony 2.4 comes out (it's being developed at the moment and it has no stable releases yet).
In Symfony2.4 you will be able to use RequestStack.
However, I've put quotes around impossible for a reason, because it is doable, but it isn't pretty:
So basically your service should look something like this:
<?php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
class AcmeRequestListener
{
/**
* @var string
*/
private $route;
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
$this->route = $event->getRequest()->get('_route');
}
}
}
Now, since I see you need route name in your template, you can make it extend twig extension, and of course tag it as twig extension:
<?php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
class AcmeRequestListener extends \Twig_Extension
{
/**
* @var string
*/
private $route;
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
$this->route = $event->getRequest()->get('_route');
}
}
public function getFunctions()
{
return [
new \Twig_SimpleFunction('current_route', function () {
return $this->route;
}),
];
}
}
This code is out of head and I haven't tested it, so sorry if i misspelled some class or function name :)
Now in your templates you should be able to do:
{% block something %}
Hi, route of my master request is: {{ current_route() }}
{% endblock %}