1

I have created a block which is having login and account link. if customer is logged out it will show login link. if the customer logged in it will show logout url. If i enable the full page it is not working properly. Even if modify in that it is not getting reflected. Then i put cacheable="false" it works fine. But if i put cacheable="false" entire page become not cacheable. In default customer login link ( Magento\Customer\Block\Account\AuthorizationLink ) does not use any cacheable="false". How is that working?

  • Have you found your answer ? I have same question. – Rutvee Sojitra Aug 20 '18 at 5:35
1

Use Knockout.js: Knockout is working in full page cache also.
If a user is not logged in then customer().firstname returns null so it does what you expect.

<li class="minicart-nav-item" data-bind="scope: 'customer'">
<!-- ko if: customer().firstname -->
     <a class="customer-name" href="#">
        Sign Out <span data-bind="text: customer().firstname"></span>
    </a>
<!-- /ko -->

<!-- ko ifnot: customer().firstname -->
    <a class="customer-name" href="#">
        Sign In
    </a>
<!-- /ko -->
</li>

<script type="text/x-magento-init">
{
"*": {
    "Magento_Ui/js/core/app": {
        "components": {
            "customer": {
                "component": "Magento_Customer/js/model/customer"
            }
        }
    }
}
}
</script>
0

Use section data instead: http://devdocs.magento.com/guides/v2.1/config-guide/cache/cache-priv-priv.html

Never use cacheable="false"unless you want all page not to be full page cached (Varnish or built-in). This is what's for cacheable="false"

  • Thats ok. But default class working without section – Krishnan Daiva Feb 23 '17 at 17:53

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.