Nested XML Menus using addLink() in Magento

Natively Magento doesn’t have a direct method to nest menu items using the page/template_links->addLink() function, but we had some menus that will never change and are best set in the layout XML rather than in the database/CMS. There is a feature to addLinkBlock() – but this relies on the block outputting the wrapping <li> – but as we intended to nest addLink(), this wouldn’t quite work. So we put together a tiny extension to offer this functionality, The files You’ll need to create the following files and directories first, ./app/code/community/Sonassi/TemplateLinks ./app/code/community/Sonassi/TemplateLinks/etc ./app/code/community/Sonassi/TemplateLinks/Block/Page/Template ./app/etc/modules/Sonassi_TemplateLinks.xml ./app/code/community/Sonassi/TemplateLinks/etc/config.xml ./app/code/community/Sonassi/TemplateLinks/Block/Page/Template/Links.php ./app/design/frontend/x/x/template/page/template/links_nested.phtml Add this to ./app/etc/modules/Sonassi_TemplateLinks.xml <?xml version=”1.0″?> <!– /* * @category Module * @package Sonassi_TemplateLinks * @copyright Copyright (c) 2012 Sonassi */ –> <config> <modules> <Sonassi_TemplateLinks> <active>true</active> <codePool>community</codePool> </Sonassi_TemplateLinks> </modules> </config> Add this to ./app/code/community/Sonassi/TemplateLinks/etc/config.xml <?xml version="1.0"?> <!– /* * @category Module * @package Sonassi_TemplateLinks * @copyright Copyright (c) 2012 Sonassi */ –> <config> <modules> … Continue reading