I am checking if customer is logged in or not(also i have to display customer name) but sometimes it's not working and after flushing block_html cache it works.

I have tried all possible solutions:-

Tried following but still getting issue:-

Why Customer Session is not working on full page cache?


As i R&D and found throgh AJAX technique it can be resolved but not any idea of the same...here are the references:-



So please help me for the same.

1 Answer 1


Take a look at this


It's the plugin


    $result['is_logged_in'] = $this->customerSession->isLoggedIn();


<div class="greet welcome" data-bind="scope: 'customer'">
    <!-- ko if: customer().is_logged_in  -->
    <span class="logged-in"
            data-bind="text: new String('<?= $block->escapeHtml(__('Welcome back %1', '%1')) ?>').replace('%1', customer().firstname)">
    <!-- /ko -->
    <!-- ko ifnot: customer().is_logged_in  -->
    <span class="not-logged-in"
            data-bind='html:"<?= $block->escapeHtml(__("Please <a href='%1'>login</a>", $block->getUrl('customer/account/login'))) ?>"'>
    <!-- /ko -->

Take a look at the how I've used the customer binding and knockout

  • thanks a ton...it's working for me. Jun 9, 2020 at 9:44
  • For the Mega Menu Section:- i am showing some "static menu" in the Mega Menu section through phtml for logged-in customer only...but for that i have to include your '<div class="greet welcome" data-bind="scope: 'customer'">' before my menu <li> due to that design get scattered...so is there any way to avoid using this div scope ? if m not using this div then your code doesn't work. Jun 9, 2020 at 9:48
  • You can use it on other elements. But beyond that you might have to have two versions the menu maybe Jun 9, 2020 at 15:31
  • Okay, i got that element must be there and i have to adjust it some where else..thankyou so much. Jun 10, 2020 at 4:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.