【问题标题】:Magento Custom Left Navigation Template displaying twiceMagento 自定义左侧导航模板显示两次
【发布时间】:2011-03-18 16:53:35
【问题描述】:

我创建了一个自定义模板(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 管理员的子类别中用一些 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 的

【问题讨论】:

    标签: php xml zend-framework magento


    【解决方案1】:

    我的猜测是您的块名称 (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>
    

    【讨论】:

    • 我不知道这对我是否有意义,但确实如此。谢谢大佬!
    • 不客气。玩得开心!两个块的块名称相同(实际上同一个块被调用/显示两次),Magento 将最后一个模板注入到唯一标识的 * 块中,因此 --> 相同的块名称显示两次,最后一个模板注入(left_parent_category .phtml) *对不起,如果这不是正确的英文...
    • @Hervé Guétin 你的回答解决了我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    相关资源
    最近更新 更多