Keeping parent menu items active in child pages |
Helo, I have this array of navigation from db, and i've already prepare the array in parent child format. So my question is, how do i keep the parent menu active when i visit the child pages. i'm using Codeigniter. the slug is dynamically defined by the user in admin panel.
here is my dummy array: PHP Code: array(3) { here is my routes setup to grab the page: PHP Code: $route['([a-zA-Z0-9_-]+)'] = 'pages/render'; for now i only success to get the menu active when visiting the root page by compare the slug with uri_segment(1) with this function: PHP Code: function get_menu ($array, $child = FALSE) Please let me know what is the correct way to achive this. Thank you very much
I use a My_Controller to render my views within a universal template view that has my nav in it. Then from within a controller I have a var called page_name that I can set with the nav name. That gets passed to the template view when rendered. Then in template view I use a shorthand IF to say if page_name = the name of my nav item, set the css class to active. Hope that makes sense. I don't have time right now to show code.
Hi I know what you mean,but that is just same as my solution right know.
(11-16-2014, 12:32 PM)alroker Wrote: I use a My_Controller to render my views within a universal template view that has my nav in it. Then from within a controller I have a var called page_name that I can set with the nav name. That gets passed to the template view when rendered. Then in template view I use a shorthand IF to say if page_name = the name of my nav item, set the css class to active. Hope that makes sense. I don't have time right now to show code. (11-16-2014, 12:32 PM)alroker Wrote: I use a My_Controller to render my views within a universal template view that has my nav in it. Then from within a controller I have a var called page_name that I can set with the nav name. That gets passed to the template view when rendered. Then in template view I use a shorthand IF to say if page_name = the name of my nav item, set the css class to active. Hope that makes sense. I don't have time right now to show code. i do something very similiar, but instead of additional shorthand IF blocks i echo out the $page_name variable to the Javascript (jquery based menu system) there is an option in the menu system i use that is: active_menu: 'MENUID/CLASSNAME'.
This is how I sat the active state in a helper file, I' am sure you can add a new method for the child pages.
PHP Code: /** active_link is your page name. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
A very simple solution and works fast. Instead of using a controller you can do it directly in the views page where your navigation (menu) file is written.
<?php $segment = $this->uri->segment(1); ?> Then in your Dropdown menu: <li class="sub-menu"> <a href="javascript:void(0);" <?php echo ($segment == 'settings-seo' || $segment == 'settings-email') ? 'class="active"' : 'class=""'?>> <i class="fa fa-cogs"></i> <span>Settings</span> </a> <ul class="sub"> <li><a href="settings-seo">Search Engines</a></li> <li><a href="settings-email">Email Template</a></li> </ul> </li> Is there a way we can paste code snippet properly in this forum? (12-18-2014, 11:41 PM)apparasenal Wrote: A very simple solution and works fast. Instead of using a controller you can do it directly in the views page where your navigation (menu) file is written. You can use these tags : Code: [php][/php] Or : Code: [code][ /code] (remove the space) |
Welcome Guest, Not a member yet? Register Sign In |