In Magento the only native navigation menu available is the product categories menu renderer, therefore you’ll need to build your own if you need any other form of navigation. Apart from the usual standard markup and link generation, a navigation menu needs to be able to check if the current page is active, however this isn’t all that straightforward, especially if you want to do it efficiently.

So which pages might we want to include in a Magento custom menu? Well, this is most commonly going to be the contacts page and some CMS pages. The contacts page has it’s own controller action, so that may give you an idea how to go about performing some form of check. However all of the CMS pages reside under a single controller action, so you would need to do something a little different there, though for either solution you would start by checking what the current route is.

You can of course hack something out in the template file if you really want to, but that would feel like a cheap and dirty solution to me and would mean that the code isn’t reusable; you may want to include a smaller collection of links elsewhere on the page for example. So, for the purpose of this tutorial I’m going to assume that you know how to build a basic Magento extension and show you how to create a basic navigation helper. If you don’t know how to build an extension I plan to cover this in a future article.

Navigation utility helper class

The helper class below is pretty basic and for good measure I’ve included an additional method if you happen to be using the aheadworks Blog extension.

Example template usage

 

Tutorial

LEAVE A COMMENT

Notify of
avatar
wpDiscuz