Magento自定义左侧导航模板显示两次

时间:2010-07-20 21:48:12

标签: php xml zend-framework magento

我创建了一个自定义模板(mytheme / template / catalog / navigation / left_parent_category.phtml)来显示当前类别的父类别。

<?php


echo '<div class="box base-mini">';
echo '<ol>';
    $currentCat = Mage::registry('current_category');

    if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
    {
        // current category is a toplevel category
        $loadCategory = $currentCat;
    }
    else
    {
        // current category is a sub-(or subsub-, etc...)category of a toplevel category
        // load the parent category of the current category
        $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
    }
    $subCategories = explode(',', $loadCategory->getChildren());

    foreach ( $subCategories as $subCategoryId )
    {
        $cat = Mage::getModel('catalog/category')->load($subCategoryId);

        if($cat->getIsActive())
        {
            echo '<li><a href="'.$cat->getURL().'">'.$cat->getName().'</a></li>';
        }
    }
echo '</ol>';
echo '</div>';

?>

我在magento admin的子类别中覆盖了一些xml的布局:

<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>

php和xml正在正确地执行所有操作,但由于某种原因它会显示两次。我不知道为什么这个模板会被调用两次。任何帮助将不胜感激。

PS ......这适用于Magento 1.3

1 个答案:

答案 0 :(得分:6)

我的猜测是您的块名称(catalog.leftnav)与布局XML中名为catalog.leftnav的另一个块冲突。实际上,catalog.xml中有一个catalog.leftnav块。

尝试更改您的块名称。即,在magento admin的子类别中:

改变
<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>

<reference name="left">
            <block type="catalog/navigation" name="catalog.myniceleftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>