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.

Related posts:

  1. How to Change the Footer Links in Magento
  2. How to Add a Static Block to Your Magento Theme
  3. Show All Products in a Magento Category by Default
  4. Add Increase and Decrease Quantity Buttons to Items in Magento Cart
  5. Magento Themes: Using locales with translate.csv
This entry was posted in Magento Development. Bookmark the permalink.

2 Responses to Top Links in Magento 1.4.1 Have Changed

  1. handoyo says:

    Hi there,i wonder how to add a styled search box into the top links?Thanks…

  2. Tom Robertshaw says:

    Hi Handoyo. Assuming you still have the default search box in the header, the simplest way would be to move it with some extra css. Do you have something that I can look at?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">