【问题标题】:How do I add links to Magento top.links that redirect to another domain?如何添加指向重定向到另一个域的 Magento top.links 的链接?
【发布时间】:2011-03-30 19:53:14
【问题描述】:

我可以使用保存在 ../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>

以上代码将创建一个名为 example 的链接,指向 http://myexampledomain.com/example。如果我改变这行代码

<url>example</url>

到

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

我最终得到了一个名为 example 的链接,该链接指向 http://myexampledomain.com/http:/myotherexampledomain.com。我尝试将 prepare 参数设置为 false 并通过查看 ../app/code/core/Mage/Core/Model/Url.php 将各种参数添加到 urlParams 无济于事。

【问题讨论】:

    标签: magento-1.4 magento


    【解决方案1】:

    所以,我一直在做这件事,我已经让它工作了。基本上,准备需要取消设置,因为如果将其设置为“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 中删除了 helper="core/url/getHomeUrl",因为在这种情况下不需要 getHomeUrl 函数。上面的代码创建了一个名为 example 的链接,该链接正确指向 http://myotherexapmpledomain.com。

    【讨论】:

    • 解决了我的问题。值得注意的是,您必须提供 addLink 方法所需的所有参数,因为如果列表中缺少一个参数,则 XML 将忽略它之后的所有参数。
    猜你喜欢
    • 1970-01-01
    • 2020-04-23
    • 2021-04-23
    • 2017-08-21
    • 2017-12-12
    • 2014-08-28
    • 2011-07-17
    • 2013-09-02
    • 2016-07-24
    相关资源
    最近更新 更多