我在catalog/navigation/vert_nav.phtml中尝试了以下两种方法来添加或抑制特定于主页的内容:
if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))):
or
if(
Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'
) :
两者都工作正常,但是当 BLOCK_HTML 缓存打开时,它首先工作,然后过了一会儿主页开始显示仅供其他页面使用的内容(在 else 子句之后我使用 lower down)。当我关闭 BLOCK_HTML 时,它的行为符合预期。
有趣的是,我在 page/html/head.phtml (对于主页特定的 javascript/css)和 page/html/header.phtml (对于只应出现在标题横幅上)使用了相同的代码(第一个)主页),即使 BLOCK_HTML 为 ON,这些也能正常工作。
(Magento 1.4.1.1)
上面的答案是最好的解决方案。
您只需复制 app/code/core/Mage/Catalog/Block/Navigation.php
to:
应用程序/代码/本地/法师/目录/块/Navigation.php
然后如上所述更改 getCacheKeyInfo() 方法。
/**
* Get Key pieces for caching block content
*
* @return array
*/
public function getCacheKeyInfo()
{
$shortCacheId = array(
'CATALOG_NAVIGATION',
Mage::app()->getStore()->getId(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
'template' => $this->getTemplate(),
'name' => $this->getNameInLayout(),
$this->getCurrenCategoryKey(),
// Your logic to make home/none home have different cache keys
Mage::getSingleton('cms/page')->getIdentifier() == 'home' ? '1' : '0'
);
$cacheId = $shortCacheId;
$shortCacheId = array_values($shortCacheId);
$shortCacheId = implode('|', $shortCacheId);
$shortCacheId = md5($shortCacheId);
$cacheId['category_path'] = $this->getCurrenCategoryKey();
$cacheId['short_cache_id'] = $shortCacheId;
return $cacheId;
}
这将使主页/非主页页面的缓存键不同,这将缓存两个副本,而不是缓存单个模板副本以在所有页面上使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)