更新时间:2023-12-03 22:31:46
在Twig
中做如下检查:
{% if app.user %}
<li><a href="{{ path('logout') }}">{{ 'menu.logout'|trans }}</a></li>
{% else %}
<li><a href="{{ path('login') }}">{{ 'menu.login'|trans }}</a></li>
{% endif %}
如果您有不同的角色,并且希望根据用户角色呈现页面的某些部分,您可以进行下一步检查:
In case if you have different roles and you'd like to render some parts of the page dependent on user role, you can do next check:
{% if is_granted('YOUR_ROLE') %} ... {% endif %}