Magento add wishlist_link to different block?

懵懂的女人 提交于 2019-12-06 03:31:26

问题


I have removed the wishlist link from my top.links using my local.xml file:

<remove name="wishlist_link"/>

How do I add it elsewhere, for example in my minibasket?


回答1:


In the block view script I added the following which added a link to /wishlist/.

<a href="<?php echo $this->getUrl('wishlist') ?>">Wishlist</a>



回答2:


You might want to have a look at the class 'Mage_Page_Block_Template_Links'. In this class you can see the following method:

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;
}

this is the function to add a link to the protected variable $_link; later this link will be written by your template with a foreach loop.

You can retrieve the value of this variable with:

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

for example in the file ;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; ?>

Then, you can create a new function for your custom block, or you can extend this block and use the functions removeLinkByUrl and addLink.



来源:https://stackoverflow.com/questions/11523489/magento-add-wishlist-link-to-different-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!