Magento – Link display only when signed / is logged

PictureIt is surprisingly often the case, that was forgotten in a template to incorporate a logout link. If the customer is logged, he can not get out. Thus, one should enter a logout link, which is of course only appears, if the user is logged on.

If it's just a (or more) simple links is, to be exclusively displayed, If you are logged in, this can be done with a very simple code snippet, which is simply written to the appropriate file phtml.

Example header.phtml in the folder app / design / frontend / rwd / default / template / page / html

PictureHere I would like to have a logout link next to the account link – but only if you are logged.

To this end, I add

<?php if (Magus::getSingleton('Customer / session')->isLoggedIn()) : ?>
<a href="<?php echo $this->helper('customer')->getLogoutUrl(); ?>" data-target-element="#header-account" class ="skip-link skip-account">
<span class="icon"></span>
<span class="label"><?php echo $this->__('Logout'); ?></span>
</a>
<?php endif; ?>

hinter

<a href="<?php echo $this->helper('customer')->getAccountUrl(); ?>" data-target-element="#header-account" class ="skip-link skip-account">
<span class="icon"></span>
<span class="label"><?php echo $this->__('Account'); ?></span>
</a>

a.

Of course, the icon would have to be adjusted. This is just a copy of the account links with adaptation for use as logout link.

A contribution how to integrate a mini log-in area in the side, there here.

Used in Magento Version 1.9 Comments? Additions? Notes? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

Leave a Reply

Your email address will not be published. Required fields are marked *