5

我已经使用我的 local.xml 文件从我的 top.links 中删除了愿望清单链接:

<remove name="wishlist_link"/>

如何将它添加到其他地方,例如在我的迷你篮中?

4

2 回答 2

13

在块视图脚本中,我添加了以下内容,其中添加了指向/wishlist/.

<a href="<?php echo $this->getUrl('wishlist') ?>">Wishlist</a>
于 2012-10-24T11:14:39.863 回答
0

您可能想查看“Mage_Page_Block_Template_Links”类。在这个类中,您可以看到以下方法:

public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(),
    $position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='')
{
    if (is_null($label) || false===$label) {
        return $this;
    }
    $link = new Varien_Object(array(
        'label'         => $label,
        'url'           => ($prepare ? $this->getUrl($url, (is_array($urlParams) ? $urlParams : array())) : $url),
        'title'         => $title,
        'li_params'     => $this->_prepareParams($liParams),
        'a_params'      => $this->_prepareParams($aParams),
        'before_text'   => $beforeText,
        'after_text'    => $afterText,
    ));

    $this->_links[$this->_getNewPosition($position)] = $link;
    if (intval($position) > 0) {
         ksort($this->_links);
    }

    return $this;
}

这是添加到受保护变量 $_link 的链接的函数;稍后,此链接将由您的模板使用 foreach 循环编写。

您可以使用以下方法检索此变量的值:

public function getLinks()
    {
        return $this->_links;
    }

例如在文件 ;page/template/links.phtml

<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
    <?php foreach($_links as $_link): ?>
        <?php if ($_link instanceof Mage_Core_Block_Abstract):?>
            <?php echo $_link->toHtml() ?>
        <?php else: ?>
            <li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
        <?php endif;?>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

然后,您可以为自定义块创建一个新函数,或者您可以扩展此块并使用函数 removeLinkByUrl 和 addLink。

于 2012-07-17T14:43:21.450 回答