jquery - Active status of custom added top-menu items [Magento topmenu] -


to add "home" menu item , other after categories menu items : in file project\app\design\frontend\rwd\default\template\page\html\topmenu.phtml adding 2 blocks home-link , post-menu-links

<nav id="nav">         <ol class="nav-primary">             <?php echo $this->getlayout()->createblock('cms/block')->setblockid('home-link')->tohtml(); ?>             <?php echo $_menu ?>             <?php echo $this->getlayout()->createblock('cms/block')->setblockid('post-menu-links')->tohtml(); ?>         </ol> </nav> 

and adds menu items accordingly how maintain active state adding "active" class on active menu item added via these blocks ?

what tried

i tried using via jquery cookies on click setting menu(li) index in jquery cookies. fails

  • when clicking , stopping load

  • or coming later on site (previous cookies being active active sign on wrong menu item.)

in template file: project\app\design\frontend\rwd\default\template\page\html\topmenu.phtml if links lead cms pages, should find out current page identifier. <li id="the-cms-link"> <a href="/the-cms-link">the cms link</a> </li> //then in php below menu: <script> var currentpageid = ''; <?php if (mage::getsingleton('cms/page')): ?> currentpageid = '<?php echo mage::getsingleton('cms/page')->getidentifier(); ?>' <?php endif; ?> if (jquery('#'+currentpageid).is('li')) { jquery('#'+currentpageid).addclass('active'); } </script> can page id also, remember need setup <li> id cms block. in case using different links, such ones custom modules, need find out current module, controller , action , check if match of links use jquery again set active class. current module, controller , action: $modulename = mage::app()->getrequest()->getmodulename(); $controllername = mage::app()->getrequest()->getcontrollername(); $actionname = mage::app()->getrequest()->getactionname();


Comments