使用xml magento添加指向顶级菜单的链接

时间:2013-04-18 07:26:59

标签: xml magento-1.7

我尝试使用xml将我的自定义链接添加到顶级菜单但是它没有用。我之前使用过此代码并且工作正常,但现在我坚持使用它。我的xml代码是:

<default>
          <reference name="top.links">           
            <block type="articles/links" name="articles"/>
           <action method="addLinkBlock" ><blockName>articles</blockName></action>
        </reference> 
                <reference name="footer_links">
                     <block type="articles/links" name="articles"/>
            <action method="addLinkBlock"><blockName>articles</blockName></action>
                </reference>

    </default>

我的区块代码是:

class My_Articles_Block_Links extends Mage_Core_Block_Template
{
    protected function _toHtml()
    {
        $html ='';      

        if(Mage::helper('articles')->getArticlesEnable()){


        if(in_array(Mage::app()->getStore()->getStoreId(),Mage::helper('articles')->getscopeid())){

                $html.= '<li><a  href="'.Mage::helper('articles')->getUrl().'">Articles</a></li>';    
                return $html;
            }
        }

        return $html;
    }



}.

阻止代码很好并且经过测试。只有xml代码问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

因为你有动作标签 它将检查来自addActionLayoutHandles()

的功能

所以,而不是过度_toHtml() 只需添加一个功能

function addLinkBlock(){ $parentBlock = $this->getParentBlock(); $parentBlock->addLink('whatever link you want to add'); }