Top Links in Magento 1.4.1 Have Changed

In previous versions of Magento the top links, i.e.

    * My Account
    * My Wishlist
    * My Cart
    * Checkout
    * Log In

were called in:

/app/design/frontend/[interface_name]/[theme_name]/template/page/html/top.links.html

In this file, the $toplinks array was looped through and a list of links are echoed. The proper way to then add extra links to this array is by the addLink method in the appropriate layout file. As some of you will notice this is similar in fashion to the footer links as I described in a previous post.

The block that was used to define the toplink could be found in:

/app/code/core/Mage/Page/Block/Html/Toplinks.php

This has now been deprecated, and the toplinks now follow the more generic links template in:

app/code/core/Mage/Page/Block/Template/Links.php

So, if you were ever tempted to just hack an <li> element in the top links foreach loop, there’s no doing that any more you naughty girls and boys! Use Magento’s built in awesomness, that’s why it’s there!

As an example, in a recent /layout/page.xml file I had the code below to add “help” and “contact us” links.

                <block type="page/template_links" name="top.links" as="topLinks">
                    <action method="addLink" translate="label title"><label>help</label><url>help</url><title>help</title><prepare/><urlParams/><position>100</position></action>
                    <action method="addLink" translate="label title"><label>contact us</label><url>contacts</url><title>contact us</title><prepare/><urlParams/><position>10</position></action>
                </block>

Easy as pie.

Posted by Tom.

About Tom: Magento Loving Managing Director at Meanbee. Main tasks include coding magento themes, drinking tea and reminding Nick what he should be doing.

View the original version of this post.

Leave a Reply

  • You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tweets from @meanbee

Contact Meanbee

Send us your message