简体   繁体   English

启用缓存后页脚上的 Magento CMS 块不起作用

[英]Magento CMS block on footer not working after cache enable

I'm trying to show a Magento CMS block only one home page footer area, I'm using below code我正在尝试仅显示一个 Magento CMS 块一个主页页脚区域,我正在使用以下代码

$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我尝试了一些关于堆栈溢出的解决方案,但没有奏效,我的 Magento 版本是 1.9.2.4

Anyone know how to fix this issue please任何人都知道如何解决这个问题

You should use layout handles to conditionally add blocks to layout (probably from your theme's local.xml ):您应该使用布局句柄有条件地将块添加到布局(可能来自您主题的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如果你没有local.xml ,不要忘记把上面的代码用

<?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.祝你好运。

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ć这看起来像是 Magento 1.9 版本上的一个已知错误,感谢大家帮助我,特别是 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM