[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.