Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2: How do I check if a user is not logged in inside a template?

In Symfony 2 templates (using Twig), how can I effectively check whether a user is not logged in?

I don't want to use ROLE checks. I want a straightforward way to check if a user is not logged in.

I'm aware that comparing app.user.username with anon works, but that just doesn't feel right to me.

like image 435
Tool Avatar asked Mar 12 '12 01:03

Tool


1 Answers

You can check if app.user is set.

 {% if app.user %}     # user is logged in  {% else %}     # user is not logged in  {% endif %} 
like image 147
Checksum Avatar answered Sep 18 '22 08:09

Checksum