I'd like to add the categories description into the topmenu navigation on Magento.
I've tried a hack using CMS block but it didn't work properly (it shows category but outside of topmenu) Do you have any any clue about how doing this easily?
Thanks for your help.
Quick summary: (Magento 1.8.2.0 and higher) (see last paragraph for earlier versions)
Add a child block under the
top.menublock in your theme's local.xml and create (or copy from RWD theme) a custom renderer.phtml file to generate your custom menu HTML that includeds category descriptions.The recommended path for renderer.phtml is
app/design/frontend/yourpackage/default/template/page/html/topmenu/renderer.phtml.Detail:
If you have Magento 1.8.2.0 or above you should seek to implement a menu
renderer.phtmlfile due to this code:You can see here that if there is a child block named
catalog.topnav.rendererthen Magento will use it, otherwise it falls back gracefully to use$this->_getHtml()where$thisisMage_Page_Block_Html_Topmenu.Unfortunately the Magento default theme does not use the new renderer feature so there is not an example in the base theme. However the most excellent RWD theme which comes as standard with Magento does use the menu renderer and I highly recommend you study the RWD theme code to learn how to use a menu renderer phtml file.
Specifically you should create an additional entry in your local.xml to define your menu renderer:
Or something like that to suit your theme layout. Noting specifically the all-important hard coded child block name
name="catalog.topnav.renderer"And then I would start with a copy of the RWD
renderer.phmlfile copied into your theme pathpage/html/topmenu/renderer.phtmlAnd by studying that file you can start to see where and how various modifications affect the menu html.
Please note the code that
Mage_Page_Block_Html_Topmenu_Renderer::render()uses to handle your rendrerer.phtml file: unusually for Magento it is a directinclude $this->_templateFileand either returns the string or the ob_get_cleaned buffer:If you are using a version prioir to 1.8.2.0 you will need to rewrite the class
Mage_Page_Block_Html_Topmenuand override its function_getHtml()to inject your extra HTML into the menu. The main disadvantage being you need to recompile every time the menu layout changes.