Symfony2 + Twig get real/full current route
routes, symfony, twig
Solution
The `Request` class has a `getRequestUri()` method. You can access it in twig like
{{ app.request.requesturi }}
Problem
I have a routing with optional parameters: ``` /** * @Route( "/route/{id}", name="_route", defaults={"id" = ""} ) * @Template() */ ``` In the template I have a form and I want the form to be send to either: ``` /route ``` or: ``` /route/10 /route/10/mail – if there were more than just one parameter ``` At the moment I'm solving it like this: ``` {{ path(app.request.attributes.get('_route')) }}/{{ object.id }} ``` Which works fine, but I have to add all possible parameters by myself. Is there a way to get the full current path from within twig? I don't want to add an extra variable in my controller to be send to the template.