我正在使用magento 1.7.0.2,我遇到了一个问题并且谷歌了解所有解决方案但不适合我...
我的问题是我想在我的2Column-left.phtml布局中添加条件。 就像我想要显示这些内容如果我在主页上
**<div><?php echo $this->getChildHtml('sectionA') ?></div>**
<div class="product-content section-content-2">
<div class="container">
<div class="col-left sidebar">
<?php echo $this->getChildHtml('left') ?>
</div>
<?php echo $this->getChildHtml('content') ?>
</div>
</div>
如果我不在主页上,那就是这个:
<div class="product-content section-content-2">
<div class="container">
<div class="col-left sidebar">
<?php echo $this->getChildHtml('left') ?>
</div>
<?php echo $this->getChildHtml('content') ?>
**<div><?php echo $this->getChildHtml('sectionA') ?></div>**
</div>
</div>
我使用了所有解决方案:
http://dltr.org/blog/magento/187/Magento-How-to-find-if-you-are-on-homepage-getIsHomePage
Detect home page in Magento .phtml that will work with BLOCK_HTML cache enabled
但没有工作......请帮助并建议我应该做什么或者我是否犯了错误???
感谢
答案 0 :(得分:1)
$action = Mage::app()->getFrontController()->getAction()->getFullActionName();
if($action=='cms_index_index'){
echo "home";?>
<div><?php echo $this->getChildHtml('sectionA') ?></div>**
<?php } ?>
<div class="product-content section-content-2">
<div class="container">
<div class="col-left sidebar">
<?php echo $this->getChildHtml('left') ?>
</div>
<?php echo $this->getChildHtml('content') ?>
</div>
</div>
非主页:
<div class="product-content section-content-2">
<div class="container">
<div class="col-left sidebar">
<?php echo $this->getChildHtml('left') ?>
</div>
<?php echo $this->getChildHtml('content') ?>
<?php
$action = Mage::app()->getFrontController()->getAction()->getFullActionName();
if($action!='cms_index_index'){ ?>
<div><?php echo $this->getChildHtml('sectionA') ?></div>
<?php } ?>
</div>
</div>
答案 1 :(得分:1)
在标题phtml文件中:
if($this->getIsHomePage()) {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
在其他phtml文件中:
if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
答案 2 :(得分:0)
您可能想看看Magento如何处理这个问题。班级 Mage_Page_Block_Html_Header 中的第46行显示:
/**
* Check if current url is url for home page
*
* @return true
*/
public function getIsHomePage()
{
return $this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true));
}