Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add links to Magento top.links that redirect to another domain?

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.

like image 595
JP1971 Avatar asked Mar 30 '11 19:03

JP1971


People also ask

What is URL rewrite in Magento 2?

What is URL Rewrite? URL Rewrite is one of the most awesome tools by Magento 2 that allows you to edit any URL linking to a product, category or CMS page. After enabling the rewrite, the visitors who access the old link will be navigated to the new address to get more information.


1 Answers

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.

like image 163
JP1971 Avatar answered Nov 02 '22 15:11

JP1971