1
votes

Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The "app.security" variable is not available.") in SonataAdminBundle::standard_layout.html.twig at line 183.

Now I did not think that this was possible, app being a Twig global, and have no idea where to start. I am trying to configure Sonata User Bundle: FOS User Bundle and Sonata Admin Bundle with little success.

EDIT I removed the SonataUserBundle and went back to a configuration that I know worked in other projects. This isolated the problem as being Symfony and Twig specific rather than an error in my configuration; so I have removed my config files.

For anyone else who hits this problem: app.security is deprecated from 2.6 and was supposed to be removed in 3.0. However someone has broken the BC layer and the container is not injected any more so the effect is that app.security has been removed in 2.8 and not in 3.0. See https://github.com/symfony/symfony/issues/18223 and https://github.com/symfony/symfony/commit/bf066dace2922cf1ce335f5f683fc63d5a7e23c2. I don't know if or when this will be fixed.

Meanwhile my solution was to completely override the SonataAdminBundle::standard_layout.html.twig and remove the calls to app.security as per the migration to 3.0 instructions: http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements

Lastly, this change also deprecates the app.security global variable for Twig templates. You should use instead the app.user global variable and the is_granted() function.

1

1 Answers

0
votes

This is a bug in the Twig Bridge which may be fixed at some date: https://github.com/symfony/symfony/issues/18223 https://github.com/symfony/symfony/commit/bf066dace2922cf1ce335f5f683fc63d5a7e23c2

Meanwhile my solution was to completely override the SonataAdminBundle::standard_layout.html.twig and replace the calls to app.security with app.user as per the migration to 3.0 instructions: http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements