cancel
Showing results for 
Search instead for 
Did you mean: 

Do not want to cache dynamic content in static block (1.9.2.1)

Do not want to cache dynamic content in static block (1.9.2.1)

Hello!

 

I have 1.9.2.1 CE installed and everything works great. But before I had 1.9.0 and my static blocks could load dynamic content without it being cached. But in version 1.9.2.1 this dynamic content is cached as well... is this working as intended? I guess so? Perhaps the static blocks never were cached before?

 

For example I have a block that loads sub-categories like this:

<div>{{block type="catalog/navigation" name="catalog.navigation" template="catalog/navigation/sub-categories.phtml"}}</div>

In my category settings I choose this block at Display settings->CMS block but since this block is now cached I get the same sub-categories on every page.

 

Can I exclude caching some blocks? Or is it any other way I can do this?

5 REPLIES

Re: Do not want to cache dynamic content in static block (1.9.2.1)

Due to the way static blocks are loaded for categories, this is not really possibly in the flow you are describing. A quick look at the code shows that there is no real way of intercepting the rendering of the static block to modify the cache timing (Mage_Catalog_Block_Category_View::getCmsBlockHtml) :

 

 

    public function getCmsBlockHtml()
    {
        if (!$this->getData('cms_block_html')) {
            $html = $this->getLayout()->createBlock('cms/block')
                ->setBlockId($this->getCurrentCategory()->getLandingPage())
                ->toHtml();
            $this->setData('cms_block_html', $html);
        }
        return $this->getData('cms_block_html');
    }

 

 

If you have a access to your theme's layout xml files, you can try a workaround we've used in the past. This workaround revolves around setting the cache key based on the current url. The cache key is an identifier that defines what makes a certain block unique. This will require you to add a static block to your category view page (in your theme's local.xml), like so:

 

<reference name="category.products">
    <block type="cms/block" name="category.subs">
        <action method="setBlockId"><id>your-block-id-goes-here</id></action>
        <action method="setCacheKey"><key helper="core/url/getCurrentUrl" />
    </block>
</reference>

 

You then need to edit your theme's catalog/category/view.phtml template file and add the following in the place where you want this block to show:

 

<?php echo $this->getChildHtml('category.subs'); ?>

I do realise that this is a bit more involved than simply changing the static block content and linkage in the CMS, but hopefully it'll be of some use to you!

 

 

Problem solved? Click Accept as Solution!
www.iweb.co.uk | Magento Small Business Partner

Re: Do not want to cache dynamic content in static block (1.9.2.1)

I've tried your suggestion, but it still shows the same subcategories for every category. Even though the setCacheKey is unique for every page. 

Re: Do not want to cache dynamic content in static block (1.9.2.1)

Hi,

 

Bas's example local.xml change is missing a </action> on the fourth line - if you make sure you have that and can confirm you've cleared your caches since making the changes to the XML *and you're still seeing the error* then it may need to wait for him to come back with an answer,

 

Aaron

Problem solved? Click Accept as Solution!
www.iweb.co.uk | Magento Small Business Partner

Re: Do not want to cache dynamic content in static block (1.9.2.1)

Yes I noticed it missed a </action> and I also cleared the cache

Re: Do not want to cache dynamic content in static block (1.9.2.1)

Instead of using a static block at all, add your dynamic content block using the category's layout XML update like so:

 

<reference name="content">
    <block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"/>
</reference>

Then you can set the category to show only a static block, but simply don't select a static block (leave it on "Please select a static block ...")

This way the block class can set its cache tag correctly.