2

我已经很好地搜索并找到了customer_logged_inandcustomer_logged_out标签,但我无法让它们正常工作,我敢肯定这是我对它们的误解。

top.links我的目标是在用户未登录时块中隐藏登录、帐户和结帐链接,并在用户登录显示它们。

我在local.xml文件末尾放置了以下内容,以尝试删除登录链接:

    <customer_logged_in>
        <reference name="top.links">
            <action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
        </reference>
    </customer_logged_in>

</default>

但它不起作用。有人可以解释为什么这不起作用吗?这让我疯狂!

4

2 回答 2

7

在我的情况下,删除 local.xml 中的链接有效。这是代码:

<customer_logged_in>
    <reference name="top.links">
        <action method="removeLinkByUrl"><url helper="customer/getLogoutUrl"/></action>
    </reference>
</customer_logged_in>
<customer_logged_out>
    <reference name="top.links">
        <action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
    </reference>
</customer_logged_out>
于 2013-03-29T12:35:08.753 回答
3

好的,我找到了原因,首先它们是顶级标签,不应该放在默认标签中,其次它在 local.xml 中不起作用,所以我将代码放在 customer.xml 的顶部,然后它是一种享受。注意:我删除了添加到 top.links 链接的 xml,这似乎会干扰它。

工作xml:

<!--
Load this update on every page when customer is logged in
-->

    <customer_logged_in>
        <reference name="top.links">
            <action method="addLink" translate="label title" module="checkout"><label>My Cart</label><url helper="checkout/cart/getCartUrl"/><title>My Cart</title><prepare/><urlParams/><position>9</position></action>
            <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
            <action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
        </reference>
    </customer_logged_in>

<!--
Load this update on every page when customer is logged out
-->
    <customer_logged_out>
        <reference name="top.links">
            <action method="addLink" translate="label title" module="customer"><label>Sign up</label><url helper="customer/getRegisterUrl"/><title>Register </title><prepare/><urlParams/><position>100</position></action>
            <action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
            <action method="removeLinkByUrl"><url helper="checkout/url/getCheckoutUrl"/></action>
            <action method="removeLinkByUrl"><url helper="checkout/cart/getCartUrl"/></action>         
            <action method="removeLinkByUrl"><url helper="customer/getLogoutUrl"/></action>
        </reference>
    </customer_logged_out>
于 2012-05-25T13:06:11.940 回答