0

I'm wondering if it is possible to hole punch the block cache, or if I need to rethink how the block is being included. The PHTML file is being brought in with a _parepLayout() method in a module (extended off of Mage_Catalog_Block_Category_View).

protected function _prepareLayout()
{
    parent::_prepareLayout();

    if ($this->isMixedMode()) {
        if(!$this->getRequest()->getParam('listing')){
            $root = $this->getLayout()->getBlock('root');
            $root->setTemplate('page/1column.phtml');
            $root->unsetChild('left');

            $this->_addChildBlock('something_categorylisting/subcategory_listing', 'something.subcategory.listing', 'subCatListing', 'something/subcat_listing.phtml');
        }else{
            // Add cart blocks to product listing page
            $this->_addChildBlock('another_multicart/addtocart', 'another.catalogaddtomulticart', 'catalogaddtomulticart_addtocart', 'something/multicart/addtocart.phtml');

            $this->_addChildBlock('core/template', 'another.catalogaddtocart', 'catalogaddtocart_addtocart', 'catalog/category/categoryaddtocart.phtml');
        }
    }

    return $this;
}

I'm trying to hole punch the subcat_listing.phtml block. In it is some conditions to show certain buttons on the page based on a count. I am completely lost on how to accomplish this. I've tried methods found on Google and in other code samples. Does anyone have any direction on where to begin doing this? Doesn't have to be a complete solution. I just need a base to go from on solving this.

1

Always use the layout XMLs to include blocks, the block cache will handle this better than including blocks via code.

If not possible, then, to prevent caching add a getCacheLifetime method the the Block class.

public function getCacheLifetime()
{
   return 0;
}

which will tell Magento to not cache the block.

  • That actually didn't work. I can see that it extends it from the Mage_Core_Block_Abstract class. My first run with the debugger on does break at the return 0 line, but after that it doesn't. Is there any more to this? Do I need to also build a cache.xml file and the others? – Dan Joseph Jun 22 '15 at 15:29
  • Are you sure your problem is the block cache? Not any Full page cache? – Fabian Blechschmidt Jun 24 '15 at 17:25
  • Nope, not sure, but a possible solution – Sander Mangel Jun 24 '15 at 17:46

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.