缓存启用后页脚上的 Magento CMS 块不起作用
Magento CMS block on footer not working after cache enable
我正在尝试仅显示一个 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();
}
此代码在我禁用缓存时工作正常,但在启用缓存后它显示在所有页面上,有时不显示在任何页面上。
我尝试了几个关于堆栈溢出的解决方案,但都没有用,我的 Magento 版本是 1.9.2.4
谁知道如何解决这个问题
您应该使用布局句柄有条件地向布局添加块(可能来自您的主题 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>
如果你没有local.xml
,别忘了用
包裹上面的代码
<?xml version="1.0"?>
<layout version="0.1.0">
... layout handle code...
</layout>
之后,您所要做的就是在页脚模板中输出您的块:
echo $this->getChildHtml('footer.seo');
这样您就可以避免在模板中进行骇人听闻的检查。
祝你好运。
我解决了在引用标签内使用操作标签从页脚中删除现金的问题,
这看起来像是 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>
我正在尝试仅显示一个 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();
}
此代码在我禁用缓存时工作正常,但在启用缓存后它显示在所有页面上,有时不显示在任何页面上。
我尝试了几个关于堆栈溢出的解决方案,但都没有用,我的 Magento 版本是 1.9.2.4
谁知道如何解决这个问题
您应该使用布局句柄有条件地向布局添加块(可能来自您的主题 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>
如果你没有local.xml
,别忘了用
<?xml version="1.0"?>
<layout version="0.1.0">
... layout handle code...
</layout>
之后,您所要做的就是在页脚模板中输出您的块:
echo $this->getChildHtml('footer.seo');
这样您就可以避免在模板中进行骇人听闻的检查。
祝你好运。
我解决了在引用标签内使用操作标签从页脚中删除现金的问题,
这看起来像是 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>