Reputation: 103
Inside Twig file I have this code:
{% set player = app.security.getToken().getUser().getPlayer() %}
{% if player.getSelectedCharacter() is not null %}
{% set character = player.getSelectedCharacter() %}
{% .... %}
{% endif %}
But at now, app.security
is deprecated. So I want to change this. I can obtain user token inside my controller and send it to the Twig. But I prefer to get it directly via Twig.
How I can do this?
Upvotes: 0
Views: 509
Reputation: 846
As you said and mentioned in the documentation.
The app.security global is deprecated as of 2.6. The user is already available as app.user and is_granted() is registered as function.
I think you can just try something like this in your view.
app.user.getPlayer()
Upvotes: 2