How to get the _locale variable inside in a Symfony layout? How to get the _locale variable inside in a Symfony layout? symfony symfony

How to get the _locale variable inside in a Symfony layout?


---UPDATED FROM THE COMMENTS---

As Symfony 2.1, you must use

{{ app.request.locale }}

or

{{ app.request.getLocale() }}

which returns app.request.locale if available and app.request.defaultLocale if app.request.locale is not set.


As Symfony 2.1 stores the "locale" in the Request instead of the session you have to use this:

{{ app.request.getLocale() }}

instead of app.session.locale


Also, you might want to simplify your routing (one single rule):

user_login:    pattern:  /{_locale}/user/login.html    defaults: { _controller: SfErrorsAppBundle:User:login }

If you want to allow only some languages you can add a requirement:

user_login:    pattern:  /{_locale}/user/login.html    defaults: { _controller: SfErrorsAppBundle:User:login }    requirements:       _locale: fr|en