0

I am trying to add sign-in in the mobile menu, so I had designed the menu according to that but when in default I had given the Sign In link once he signed in I will show the My Account link. I used the Customer View Model to check the Customer logged in or not, for me after sign in also for me sign in itself showing, so I cleared the cache at backed and checked it changed to My Account after that I logged out means it still shows My Account. I had declared the block as non-cacheable but still, I am facing this problem can any guide show the menu. I used the below code to check the Customer is logged or not

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

<?php if($customerSession->isLoggedIn() == 1): ?>
    <p>Huray, you're logged in!</p>
<?php endif; ?>

<?php if(!$isCustomerLoggedIn): ?>
    <p>Hey, you're not logged in!</p>
<?php endif; ?>
0

1 Answer 1

0

Try the below solution,

 <li data-bind="scope: 'customer'">
        <!-- ko if: customer().fullname  -->
    
            <p>Huray, you're logged in!</p>
    
        <!-- /ko -->
        
        <!-- ko ifnot: customer().fullname  -->
    
            <p>Hey, you're not logged in!</p>
    
        <!-- /ko -->
   </li>
        
        
        <script type="text/x-magento-init">
            {
                "*": {
                    "Magento_Ui/js/core/app": {
                        "components": {
                            "customer": {
                                "component": "Magento_Customer/js/view/customer"
                            }
                        }
                    }
                }
            }
            </script>

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.