0
votes

How can I disable the caching of:

Mage::getSingleton('cms/page')->getIdentifier()

I need to disable the cache for this because I want to show a static block only at the "home" page like:

<?php if (Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): ?> 
<div>
  <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-long')->toHtml() ?>
</div>
<?php endif; ?>

At the moment magento caching this page id and I can see this block on every page.

2
you put static block in footer ?Rajeev K Tomy
have you tried disabling blocks cache from system cache management.anwerj
nope this block isn't in the footer and if I disabling blocks cache it works really fine, but the problem is the page id and not the block or am I wrong?Fox

2 Answers

0
votes

Ok I found a solution:

Firstly I added the following to my local.xml:

<reference name="midcolumn">
   <block type="core/template" template="page/html/shop-description.phtml">
       <action method="setCacheLifetime"><s>null</s></action>
   </block>
</reference>

Then I created the file: shop-description.phtml with the following content:

<?php if (Mage::getSingleton('cms/page')->getIdentifier() == 'home' && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): ?>
<section class="f-fix">
    <div class="container">
        <div class="headingBox"><h2><span>About the shop</span></h2></div>
        <div class="shop-description-long">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-long')->toHtml() ?>
        </div>
        <div class="shop-description-image">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('shop-description-image')->toHtml() ?>
        </div>
    </div>
</section>
<?php endif; ?>

I don't know if it's a good solution for this problem, but it works. So any feedback would be nice :).

0
votes

Edit the "home" CMS page and put this in it's "Layout Update" field.

<reference name="content">
    <block type="cms/block" name="shop_description_long">
        <action method="setBlockId"><id>shop-description-long</id></action>
    </block>
</reference>