1

i want to remove magento top link My Account if user is not logged in ,i do not want to modify core files, i tried to get solution but could not find any working one .

i tried below method in : "Magento_Customer/layout/default.xml"

<customer_logout>
 <referenceBlock name="top.links">
 <referenceBlock name="my-account-link" remove="true" />
 </referenceBlock>
</customer_logout>

but it gives Error :

Element 'customer_logout': This element is not expected. Expected is one of ( attribute, block, referenceBlock, referenceContainer, container, move, uiComponent ).

PЯINCƎ
11.8k3 gold badges27 silver badges85 bronze badges
asked Oct 7, 2018 at 15:54
3
  • What is the Url of your My account ? Commented Oct 7, 2018 at 16:37
  • example.com/customer/account left to login Commented Oct 7, 2018 at 16:39
  • by default magento only show sign in link. once a customer log in then only it will show my account Commented Oct 7, 2018 at 17:32

2 Answers 2

1

There is no customer_logout layout handle in M2, so You can't do with xml, there is no more customer_logged_in, customer_logged_out like M1

Solution1: It's depends to your theme, try to enable the path hints, and find if you find the phtml who display "My Account" Then add if($block->customerLoggedIn()) condition arround that link.

Solution2: If your link is added via Xml, you have to create an observer with layout_load_before event, then you can add $layout->addHandle('customer_logged_in') something like:

$layout = $observer->getEvent()->getLayout();
if ($this->customerSession->isLoggedIn()) {
 $layout->getUpdate()->addHandle('customer_logged_in');
} else {
 $layout->getUpdate()->addHandle('customer_logged_out');
}

Check this link, you have a full solution.

answered Oct 7, 2018 at 17:35
0

you can't do it via layout instead you have to do it with knockout js / phtml file . Edit your theme header.phtml file in Magento_Theme/templates/html folder and add condition like this :

<li data-bind="scope: 'customer'">
<!-- ko if: customer().firstname -->
<a href="<?php echo $this->getUrl('customer/account/'); ?>" style="display:none;" data-bind="style: {display:'inline'}">
 <span class="icon-account"><i>My Account</i></span></a>
</a>
<!-- /ko -->
<script type="text/x-magento-init">
{
"*": {
 "Magento_Ui/js/core/app": {
 "components": {
 "customer": {
 "component": "Magento_Customer/js/view/customer"
 }
 }
 }
}
}
</script>
</li>
answered Oct 7, 2018 at 18:18
1
  • in header.html i see <?php echo $this->getChildHtml("top.links"); ?> where is path to edit top links file Commented Oct 9, 2018 at 19:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.