I’ve been googleing this question but I can’t find anyone with my same problem… And I don’t think I’m the only one here >.<
Let’s see, I’m using translations in symfony2. I NEED to use twig for this…
The thing is that I need 3 links so people can change the site’s language. The link has to redirect to the same page the user is, but changing the ‘_locale’.
I first thought in something like this:
// in routing.yml
bundleStuff_someUrl:
pattern: /{_locale}/aloha
defaults: { _controller: bundleStuff:Aloha:foo }
bundleStuff_fooUrl:
pattern: /{_locale}/foo/{fooParam}
defaults: { _controller: bundleStuff:Foo:foo }
// in view.html.twig
<a href="{{ path((app.request.get('_route'), { '_locale': 'l1' }) }}">lang1</a>
<a href="{{ path((app.request.get('_route'), { '_locale': 'l2' }) }}">lang2</a>
<a href="{{ path((app.request.get('_route'), { '_locale': 'l3' }) }}">lang3</a>
The problem becomes when (in this case) the _route is fooUrl… Is there a way to append every attribute I have in the current view to the path I’m looking for?
In other words referring to this example: is there a way so twig knows it has to add the ‘fooParam’ to the path if the current view is ‘fooUrl’?
Thank’s in advance!
Hope this post is useful! 😀
_route_paramsrequest attribute holds the parameters of the current route. So the twig code would be,