Can anyone tell me how to add 'sign out' option after the user is logged in on header links in Magento 2.3.X https://prnt.sc/oqe2ue
If you want to add custom logout link in header than,You can add below code in test.phtml and than call this phtml in layout
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); ?>
<?php $customerSession = $objectManager->get('Magento\Customer\Model\Session');?>
<?php if($customerSession->isLoggedIn()):?>
<li><a href="<?php echo $this->getUrl('customer/account/logout') ?>">Logout</a></li>
<?php endif; ?>
Add this phtml to lyout default.xml in theme
<referenceContainer name="header.panel.wrapper" >
<block class="Magento\Framework\View\Element\Template" name="nameOfBlock" as="header" template="Magento_Theme::test.phtml"/>
</referenceContainer>
-
Don't use Object Manager instance directly check this for more details: magento.stackexchange.com/questions/117098/… – Rakesh Donga Aug 9 '19 at 9:21
-
-
yes create data file or block file and using
\Magento\Framework\App\Http\Context $httpContext
this dependency we are getting customer login or not – Rakesh Donga Aug 9 '19 at 9:30 -
Thanx... my work is done. Can u guys tell me how to overirde block file in app folder. i want to override AuthorizationLink.php of /vendor/magento/module-customer/Block/Account. – Nafsss Aug 9 '19 at 9:53
-