8

I am able to add custom links to Magento's top.links with the following code that I save in ../myCustomTheme/layout/local.xml

<reference name="root">
<reference name="top.links">
    <action method="addLink" translate="label title">
        <label>example</label>
        <url>example</url> 
        <title>example</title>
        <prepare>true</prepare> 
        <urlParams helper="core/url/getHomeUrl"/> 
        <position>100</position>
        <liParams/>
        <aParams>class="top-link-example"</aParams>
        <beforeText></beforeText>
        <afterText></afterText>
    </action>
</reference>
</reference>

The above code will create a link named example that points to http://myexampledomain.com/example. If I change this line of code

<url>example</url>

to

<url>http://myotherexampledomain.com</url>

I end up with a link named example that points to http://myexampledomain.com/http:/myotherexampledomain.com. I have tried setting the prepare parameter to false and adding various parameters to urlParams by looking at ../app/code/core/Mage/Core/Model/Url.php to no avail.

JP1971
  • 880
  • 3
  • 10
  • 21

1 Answers1

13

So, I kept at this and I've got it working. Basically, prepare needs to be unset because, if it is set to "true" or "false", it will append the URL to your site's base URL. Here's the corrected code:

<reference name="root">
<reference name="top.links">
    <action method="addLink" translate="label title">
        <label>example</label>
        <url>http://myotherexampledomain.com</url> 
        <title>example</title>
        <prepare/>
        <urlParams/> 
        <position>100</position>
        <liParams/>
        <aParams>class="top-link-example"</aParams>
        <beforeText></beforeText>
        <afterText></afterText>
    </action>
</reference>
</reference>

I also removed helper="core/url/getHomeUrl" from urlParams because the getHomeUrl function is not needed in this case. The above code creates a link named example that properly points to http://myotherexapmpledomain.com.

JP1971
  • 880
  • 3
  • 10
  • 21
  • Solved my problem. It's worth noting that you have to supply all the arguments that the addLink method requires because if one is missing from the list, all the ones after it will be ignored from the XML. – nyaray Nov 11 '13 at 05:06