2011-03-30 85 views
8

我能够自定义链接添加到Magento的top.links用下面的代码,我保存../myCustomTheme/layout/local.xml如何添加链接到重定向到另一个域的Magento top.links?

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

上面的代码将创建一个名为例如该链接点到http://myexampledomain.com/example。如果我改变了一行代码

<url>example</url> 

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

我结束了一个链接名为例如指向http://myexampledomain.com/http:/myotherexampledomain.com。我已经尝试将prepare参数设置为false,并通过查看../app/code/core/Mage/Core/Model/Url.php来无效地向urlParams添加各种参数。

回答

12

所以,我一直在这个,我已经得到它的工作。基本上,准备需要取消设置,因为如果设置为“true”或“false”,它会将URL附加到网站的基本URL。下面是更正后的代码:

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

我也删除帮手=从urlParams“核心/ URL/getHomeUrl”,因为不需要在这种情况下getHomeUrl功能。上面的代码创建一个名为example的链接,该链接正确指向http://myotherexapmpledomain.com

+0

解决了我的问题。 值得注意的是,您必须提供addLink方法所需的所有参数,因为如果从列表中缺少一个参数,那么它之后的所有参数都将从XML中忽略。 – nyaray 2013-11-11 05:06:47

相关问题