Login and Register links in Layout


#1

Hello fellow Sylius users,

Could someone please explain how I can add “Log in” and “Register” links to my Layout, that change to ‘Log Out’ and ‘My Account’ links, once the user has logged in?

I tried the following code, but it doesn’t work.

      {% if is_granted('ROLE_USER') %}
        <a class="dark-grey-small bold" href="{{ path('sylius_shop_account_dashboard') }}">{{ 'sylius.ui.my_account'|trans }}</a>
        <a class="dark-grey-small bold" href="{{ path('sylius_shop_logout') }}">{{ 'sylius.ui.logout'|trans }}</a>
      {% else %}
        <a class="dark-grey-small bold" href="{{ path('sylius_shop_login') }}">{{ 'sylius.ui.login'|trans }}</a>
        <a class="dark-grey-small bold" href="{{ path('sylius_shop_register') }}">{{ 'sylius.ui.register'|trans }}</a>
      {% endif %}

#2

Check if the user you used for tests has ROLE_USER.
Also, it won’t work for admin users, you need separate accounts.