We’re always creating custom magento implementations for our clients and that typically starts with a local.xml file. One of our more common tasks revolves around adding and/or removing links from the “top.links” portion of the header.
Below you can see an example of a best practice when it comes to adding a new link to the top.links within Magento. The snippet does utilize some lesser known child nodes
The trick here is that the “urlParams” node in our XML below is referencing a helper class to build out the link that will eventually show up in top.links instead of hardcoding a “/” at the beginning of our “url” node.
<layout version="0.1.0"> <default> <reference name="top.links"> <action method="addLink" translate="label title"> <label>Free Shipping & Returns</label> <url>helpful-links/returns-and-exchanges</url> <title>Free Shipping And Returns</title> <prepare>true</prepare> <urlParams helper="core/url/getHomeUrl"/> <position>1</position> <aParams><id>freeshipping</id></aParams> </action> </reference> </default> </layout>
Since switching over to the structure above it’s helped our team alleviate QA issues that previously came up when migrating from one server to another and one server possibly used a different base path that included a subfolder.
- Example URL
- http://exampleproductionserver.com
http://example.stagingserver.com/store_id/