CodeIgniter Forums
How to highlight current page in menu item? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to highlight current page in menu item? (/showthread.php?tid=47584)



How to highlight current page in menu item? - El Forum - 12-14-2011

[eluser]qpixo[/eluser]
I have a menu which has generated dynamically from database. Now I want to highlight current page in menu item but when I do that all my current menu items dissappear suddently. Don't understand why?

Noticed when using $this->uri->segment(1) caused my menu dissappear.

Does anyone know how to make it works?



In my View file:

Code:
<div id="menu">
         <ul>
            &lt;?php foreach ($tabMenu as $item) : ?&gt;
                &lt;?php echo buildListItem($item); ?&gt;
            &lt;?php endforeach; ?&gt;    
        </ul>
    </div>


In my Helper file:

Code:
function buildListItem($item) {
$urlItemName = url_title($item->name, 'dash', TRUE);
$urlCatID = ($item->cat_id);
$url = base_url() . $urlItemName. "/". $urlCatID;

// item name is blog, add target into it
if ($urlItemName == 'blog') {
    $blog = "http://www.tumblr.com";
    return "<li><a href='" . $blog . "' target='_blank'>" . strtoupper($item->name) . "</a></li>";
} else {
    return "<li class='". isSelected($item).  "'><a href='" . $url . "'>" . strtoupper($item->name) . "</a></li>";
}
}

function isSelected($item) {
$urlItemName = url_title($item->name, 'dash', TRUE);

if ($this->uri->segment(1) === $urlItemName) {
    return 'menu_active';
} else {
    return '';
}
}



How to highlight current page in menu item? - El Forum - 02-27-2012

[eluser]handoyo[/eluser]
Hi qpixo,what is the solution?Thanks