I am trying to figure out how to check if a visitor is not logged in so that I can show the correct button. E.g

{% if craft.session.isLoggedIn %}
    <a href="{{ logoutUrl }}">Logout</a>
{% else %}
    {% craft.session.isGuest %}
    <a href="{{ logoutUrl }}">Client/a>
{% endif %}

What is the best method to display a "sign in" button for a visitor that takes them to a login page and then once logged in, show "Logout"?


I believe you'll want something like this...

{% if currentUser %}
    <a href="{{ url('logout') }}">Logout</a>
{% else %}
    <a href="{{ url('login') }}">Login</a>
{% endif %}
  • Thank Lindsey D, your method work perfect ! Much Appreciated May 20 '16 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.