By senzaesclusiva on
Why the twig condition snippet user.isAnonymous() doesn't work? It seems correct, referring to Drupal API.
This is my whole code
{% if not user.isAnonymous() %}
<div class="user-welcome-wrapper position-relative">
<div class="user-in" title="{{ name|striptags|trim }}">
{{ user_picture }}
</div>
<div class="my-custom-dropdown">
<a href="/user">Il mio Profilo</a>
<a href="/user/logout">Esci (Log out)</a>
</div>
</div>
{% elseif user.isAnonymous() %}
<div class="user-login-link">
<a href="/user/login" class="btn-login" title="Accedi al sito">
<span class="login-text">Accedi</span>
</a>
</div>
{% endif %}Thanks for your suggestions
Comments
Twig functions don't use
Twig functions don't use parenthesis. Try
user.isAnonymous. You can also trylogged_inContact me to contract me for D7 -> D10/11 migrations.
Thanks @jaipan, always so
Thanks @jaipan, always so kind and precise. I had dragged some PHP old habits into Twig :)
Now it works as it should.
Thanks again
Happy to have helped and know
Happy to have helped and know I have done so in the past as well :)
Contact me to contract me for D7 -> D10/11 migrations.
Hi, thanks for the
Hi, thanks for the explanation, it helps me too.