1
votes

I'm trying to show a Magento CMS block only one home page footer area, I'm using below code

$routeName = Mage::app()->getRequest()->getRouteName(); 
$identifier = Mage::getSingleton('cms/page')->getIdentifier();

if($routeName == 'cms' && $identifier == 'home') {
echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_seo')->toHtml();
} 

This code working perfectly when i disable cache, but after enable cache this shows on all pages, sometimes not display on any pages.

I tried few solutions on stack-overflow but those didn't worked , my Magento version is 1.9.2.4

Anyone know how to fix this issue please

2

2 Answers

1
votes

You should use layout handles to conditionally add blocks to layout (probably from your theme's local.xml):

<cms_index_index>
    <reference name="footer">
        <block type="cms/block" name="footer.seo">
            <action method="setBlockId"><value>footer_seo</value></action>
        </block>
    </reference>
</cms_index_index>

if you do not have local.xml, don't forget to wrap the above code with

<?xml version="1.0"?>
<layout version="0.1.0">
    ... layout handle code...
</layout>

After that, all you have to do is output your block in footer template:

echo $this->getChildHtml('footer.seo');

This way you will avoid hackish checks in your template.

Best of luck.

0
votes

I solved that using action tag inside reference tag for remove cashes from footer,

This looks like a known bug on Magento 1.9 versions, Thanks for everyone helps me specially Mladen Ilić

<reference name="footer">
    <action method="setCacheLifetime"></action>
        <block type="cms/block" name="footer.seo">
            <action method="setBlockId"><value>footer_seo</value></action>
        </block>
    </reference>