Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created January 4, 2016 21:36
Show Gist options
  • Save ryaan-anthony/dea482e25b205ab0e855 to your computer and use it in GitHub Desktop.
Save ryaan-anthony/dea482e25b205ab0e855 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<config>
<placeholders>
<your_modules_holepunch_node>
<block>your_module/your_block</block>
<name>layout.name.for.your.block</name>
<container>Your_Module_Model_Container</container>
<placeholder>PLACEHOLDER_NAME_FOR_YOUR_CONTAINER</placeholder>
</your_modules_holepunch_node>
</placeholders>
</config>
<?php
class Your_Module_Model_Container extends Enterprise_PageCache_Model_Container_Abstract
{
/**
* Override this method and return false to prevent block from being cached
* @param string
* @return bool
*/
public function applyWithoutApp(&$content)
{
return false;
}
public function applyInApp(&$content)
{
$blockClass = $this->_placeholder->getAttribute('block');
$template = $this->_placeholder->getAttribute('template');
$blockContent = $this->getBlockContent(new $blockClass, $template);
$this->_applyToContent($content, $blockContent);
return true;
}
/**
* @param Mage_Core_Block_Template
* @param string
* @return string
*/
protected function getBlockContent(Mage_Core_Block_Template $block, $template)
{
$block->setLayout(Mage::app()->getLayout());
return $block->setTemplate($template)->toHtml();
}
}
To holepunch a template, you need:
1. Cache config. (just add cache.xml to your modules /etc/ folder)
2. A container. (just rename the class; the content of the methods just render your block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment