2011-03-30 88 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

相關問題