Magento 1.9.2.0静态块显示问题? 我创建了多个静态块1.9.2.0并显示了错误的块如何解决这个问题。
答案 0 :(得分:3)
尝试以下模块可能会有所帮助
1步。创建根路径:app\etc\modules
Pankaj_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Pankaj_Cms>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Cms/>
</depends>
</Pankaj_Cms>
</modules>
</config>
2步 创建根路径:app \ code \ local \ Pankaj \ Cms \ etc
<?xml version="1.0"?>
<config>
<modules>
<Pankaj_Cms>
<version>1.0.0</version>
</Pankaj_Cms>
</modules>
<global>
<blocks>
<cms>
<rewrite>
<block>Pankaj_Cms_Block_Block</block>
<widget_block>Pankaj_Cms_Block_Widget_Block</widget_block>
</rewrite>
</cms>
</blocks>
</global>
</config>
3步创建根路径:app\code\local\Pankaj\Cms\Block
Block.php
<?php
class Pankaj_Cms_Block_Block extends Mage_Cms_Block_Block {
public function getCacheKeyInfo()
{
$blockId = $this->getBlockId();
if ($blockId) {
$result = array(
$blockId,
Mage::app()->getStore()->getCode(),
);
} else {
$result = parent::getCacheKeyInfo();
}
return $result;
}
}
4步创建根路径app\code\local\Pankaj\Cms\Block\Widget
Block.php
<?php
class Pankaj_Cms_Block_Widget_Block extends Mage_Cms_Block_Widget_Block
{
static protected $_widgetUsageMap = array();
protected function _beforeToHtml()
{
parent::_beforeToHtml();
$blockId = $this->getData('block_id');
$blockHash = get_class($this) . $blockId;
if (isset(self::$_widgetUsageMap[$blockHash])) {
return $this;
}
self::$_widgetUsageMap[$blockHash] = true;
if ($blockId) {
$block = Mage::getModel('cms/block')
->setStoreId(Mage::app()->getStore()->getId())
->load($blockId);
if ($block->getIsActive()) {
$helper = Mage::helper('cms');
$processor = $helper->getBlockTemplateProcessor();
$this->setText($processor->filter($block->getContent()));
$this->addModelTags($block);
}
}
unset(self::$_widgetUsageMap[$blockHash]);
return $this;
}
public function getCacheKeyInfo()
{
$result = parent::getCacheKeyInfo();
$blockId = $this->getBlockId();
if ($blockId) {
$result[] = $blockId;
}
return $result;
}
}
然后清除缓存