简体   繁体   中英

Magento LiteMage Cache - Excluding a block from caching

I have a Magento site with LiteMage cache on. My website share a common header at every pages. In the header, I have the following code, which checks to see if a customer is logged in to show either "Account" if logged in or "Log in" otherwise.

My problem is that, when a customer is logged in, it still shows "Log in" in some pages but "Account" at some other pages.

I believe this problem is related to my cache, how do I fix this? How do I set to exclude this particular block from caching in LiteMage, if this is how it should be fixed.

The following code is the relevant part of the codes I have at my header.phtml

<?php
        //check the user is logged on or not
        if (! Mage::getSingleton('customer/session')->isLoggedIn()){
        //if user logged on show the logout link - add this code within anchor tag
        echo '<a href="'.Mage::helper('customer')->getLoginUrl().'">'.$this->__('Log In').'</a>';
        }
        else{
        //if user is not logged on yet show the login link - add this code within anchor tag
        echo '<a href="'.$this->getUrl('friends').'">'.$this->__('Account').'</a>';
        }
      ?>

You need to identify which block contains this code. Like in default magento sample data, the login link is inside "top.links", and that block is hold punched. Try not to use the full header for it, the smaller the scope, the faster it is. Once you know the block name, you can add that in the "customized block name for top links".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM