2

I'm attempting to remove the My Account link in top.links, then reintroduce them if the customer is logged in or out with custom labels without luck. Anyone got any ideas

<reference name="root">
    <reference name="top.links">
        <action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/><position>10</position></action>
    </reference>
    <reference name="top.links">
            <customer_logged_out>
                <action method="addLink" translate="label title" module="customer"><label>Register</label><url helper="customer/getRegisterUrl"/><title>Register</title><prepare/><urlParams/><position>10</position></action>
                <remove name="checkout_cart_link" />
            </customer_logged_out>

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

    </reference>
</reference>

Edit:

I'm using Magento 1.7. To clarify, removing the My Account link works using

<action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/><position>10</position></action>

However I cannot add a new link using method="addLink".


Solution:

I copied the customer.xml from /app/design/frontend/base/layout/ into my templates layout directory and added:

<customer_logged_in>
    <reference name="top.links">
        <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>
        <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>
    </reference>
</customer_logged_in>

and

<customer_logged_out>
    <reference name="top.links">
        <action method="addLink" translate="label title" module="customer"><label>Register</label><url helper="customer/getRegisterUrl"/><title>Register</title><prepare/><urlParams/><position>10</position></action>
    </reference>
</customer_logged_out>

Ideally I'd prefer using local.xml to make these changes, but this works too.

3
  • I'm not sure to understand the question. Could you clarify?
    – ForceMagic
    Oct 16, 2012 at 2:19
  • @ForceMagic First off, I'm using magento 1.7, what I want to do is remove the default My Account link, which is done successfully when using: <action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/><position>10</position></action> However, if I want to add a new link using method="addLink", the new link does not get added. Oct 16, 2012 at 2:26
  • Ok that's great, post those informations inside your current question. You can do this by clicking on the "edit" link button. :) Add as much information as you can when you are posting question so it's easier for SO community to figure out how to solve your problem. Regards
    – ForceMagic
    Oct 16, 2012 at 2:31

1 Answer 1

0

It seems you don't need to put customer_logged_in node inside "top.links" reference. Try this one:

<customer_logged_out>
    <reference name="top.links">
           <action method="addLink" translate="label title" module="customer"><label>Register</label><url helper="customer/getRegisterUrl"/><title>Register</title><prepare/><urlParams/><position>10</position></action>
           <remove name="checkout_cart_link" />
    </reference>
</customer_logged_out>

<customer_logged_in>
    <reference name="top.links">
        <action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>10</position></action>
    </reference>
</customer_logged_in>

And also check this beautiful manual to understand fully how-to edit top.links inside local.xml: http://www.classyllama.com/development/magento-development/editing-magentos-top-links-the-better-way

3
  • I tried all of this before and it just didn't seem to work in local.xml, I ended up just copying customer.xml from the base theme and adding the links there. However it would still be nice to for me to get it to work in local.xml Oct 16, 2012 at 3:21
  • put it outside any references, just <layout><customer_logged_in></customer_logged_in></layout>
    – Sergei Guk
    Oct 16, 2012 at 3:30
  • Or just put the check in the template file?
    – pspahn
    Oct 16, 2012 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.