2

The problem is I cannot retrieve any block from layout or child block from my cached block when full page cache is enabled. I have next files: 1) cache.xml

<config>
<placeholders>
    <socialfeed_posts>
        <block>onepica_socialfeed/country_story</block>
        <name>country_story</name>
        <placeholder>SOCIAL_COUNTRY_STORY</placeholder>
        <container>OnePica_SocialFeed_Model_Cache_Container_Country_Story</container>
        <cache_life>0</cache_life>
    </socialfeed_posts>
</placeholders>
</config>

2) OnePica_SocialFeed_Model_Cache_Container_Country_Story.php

class OnePica_SocialFeed_Model_Cache_Container_Country_Story extendsEnterprise_PageCache_Model_Container_Abstract
{
protected function _renderBlock()
{
    $blockClass = $this->_placeholder->getAttribute('block');
    $template = $this->_placeholder->getAttribute('template');
    /* @var $block OnePica_SocialFeed_Block_Country_Story */
    /*$block = new $blockClass;
    $block->setTemplate($template);
    $layout = Mage::app()->getLayout();
    $block->setLayout($layout);
    return $block->toHtml();
}
}

3) OnePica_SocialFeed_Block_Country_Story.php

class OnePica_SocialFeed_Block_Country_Story extends Mage_Core_Block_Template 
{
...
public function getPager()
{
    if (null === $this->_pager) {
        $this->_pager = $this->getLayout()->getBlock('social_feed_pager');
    }
    return $this;
}
...
}

4) layout.xml

<reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
        <block type="onepica_socialfeed/html_pager" name="social_feed_pager" template="onepica/socialfeed/page/html/pager.phtml" />
<!-- Tried as a simple block of layout-->
    </reference>
    <reference name="content">
        <block type="onepica_socialfeed/country_story" name="country_story" as="country_story" template="onepica/socialfeed/country/story.phtml" >
            <block type="onepica_socialfeed/html_pager" name="social_feed_pager" template="onepica/socialfeed/page/html/pager.phtml" />
    <!-- Tried as a CHILD block of my cached block-->
        </block>
</reference>

When page load at first all be right, but when I tried reload page second time, page is crached, due to $this->getLayout()->getBlock('social_feed_pager') row. I don't want to create 'social_feed_pager' block in my Block using $this->getLayout()->createBlock('social_feed_pager'). I need retrieve block from layout.

Any help would be much appreciated. Thanks!

2
  • Maybe this will help : stackoverflow.com/questions/16852167/…. Best regards Jan 30, 2014 at 11:17
  • 1
    Unfortunately no, I used the same approach, but the problem is I can't retrieve any blocks in my cache block using $this->getLayout()->getBlock('any_block') or $this->getChild('my_child_block') Jan 30, 2014 at 12:39

1 Answer 1

3

Seems like your problem is that cache_lifetime of your block is set to '0'. That means your block is not cache at all and its code runs during each reload but all other blocks are in cache so you cannot get them like getLayout()->getBlock('any_block'). Try to set

<cache_lifetime>86400</cache_lifetime>

After clear all cache.

Your Answer

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

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