0

I've got 2 top links with the same url. I need to remove one of them on a specific handle.

Removing by url will exclude both of them.

Is there a xml solution to this? Like removing by title.

Thanks!

Example of a link:

<action method="addLink" translate="label title">
    <label>Account</label>
    <url helper="customer/getAccountUrl"/>
    <title>Account</title>
    <prepare/>
    <urlParams/>
    <position>1</position>
</action>
1

This is not supported out of the box.
The top links are rendered by the block Mage_Page_Block_Template_Links that allow you to remove a link only by url or by block.
An option would be to make your link be rendered by a block and then use removeLinkBlock.
See how to add a block in the checkout.xml layout file.
Or you can rewrite the Mage_Page_Block_Template_Links and create a new method called removeLinkByTitle

public function removeLinkByTitle($title)
{
    foreach ($this->_links as $k => $v) {
        if ($v->getTitle() == $title) {
            unset($this->_links[$k]);
        }
    }
    return $this;
}

and you can use that similar to removeLinkByUrl

1

There is no native way to remove the link by title. But you can achieve this by rewrite the class Mage_Page_Block_Template_Links.

And add the below function

public function removeLinkByTitle($title)
{
    foreach ($this->_links as $k => $v) {
        if ($v->getTitle() == $title) {
            unset($this->_links[$k]);
        }
    }
    return $this;
}

Now you can remove the link by title with below code.

<reference name="top.links">
    <action method="removeLinkByTitle"><title>Account</title></action>
</reference>
1

Instead of extending the core like the other answers, just remove them both and re-add the one you'd like to stay. For example if you've two links with the customer/getAccountUrl url:

<reference name="top.links"> 
    <action method="removeLinkByUrl">
        <url helper="customer/getAccountUrl" />
    </action>
    <action method="addLink" translate="label title">
        <label>Account</label>
        <url helper="customer/getAccountUrl"/>
        <title>Account</title>
        <prepare/>
        <urlParams/>
        <position>1</position>
    </action>
</reference>
  • Please add more details, so that the answer is useful in its own. Otherwise it would have been more suitable as a comment to one of the other answers – Fabian Schmengler Aug 13 '15 at 13:15
  • I've added a example. – Roy Aug 13 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.