Welcome Guest, Not a member yet? Register   Sign In
dynamic menu highlighting
#1

[eluser]artificialkid[/eluser]
Hi guys,

just to ask if is any thing in CI like wordpress function is_page(), is for a dynamic menu highlighting with css.

Smile
#2

[eluser]artificialkid[/eluser]
Hi guys, i made some test with the URI class, and it works,

Quote: <ol>
<li &lt;?php if($this->uri->segment(1) =='welcome'){echo "id='current'";}?&gt;><a href="lalalal" title="">home</a></li>
<li &lt;?php if($this->uri->segment(1) =='about'){echo "id='current'";}?&gt;><a href="" title="">about</a></li>
<li><a href="" title="">services</a></li>
<li><a href="" title="">work</a></li>
<li><a href="" title="">contact</a></li>
</ol>

but not at home page when I type the url, because the 1st segment of the URI is missing (default controller),

some cleus on how to do this
#3

[eluser]esra[/eluser]
Take a look at Holger's breadcrumb library (do a search for 'holger breadcrumb'). He had a similar problem, and I believe he added methods for getting and setting the first breadcrumb.
#4

[eluser]Rick Jolly[/eluser]
Maybe you'd be better to assign a "page" variable in the controller. The reason is that the controller knows what view it is loading. Using the uri segments isn't reliable because of the transparent routing that CI does when, for example, there is no controller specified in the uri, or some custom routes have been added to routes.php. Then you could do this:
Code:
<ol>
<li id="&lt;?php echo (('home' == $page): 'current' ? 'unselected'); ?&gt;"><a href="home" title="">home</a></li>
<li id="&lt;?php echo (('about' == $page): 'current' ? 'unselected'); ?&gt;"><a href="about" title="">about</a></li>
...
</ol>
#5

[eluser]artificialkid[/eluser]
Hy, each view loads otner views (parts of the page),
the header view as the site menu, footer, etc.

with your code I think that will not validate in html strict, because the idmust be unique, ok I could change each Id to dummys, but that is a workaround, I would prefer a 'correct ' way of doing that.

Any ideas, thanks
#6

[eluser]artificialkid[/eluser]
I think is solved,

Code:
<ol>
                <li><a &lt;?php if($this->uri->segment(1) =='welcome' || $this->uri->segment(1) =='' ){echo "id='current'";}?&gt; href="welcome" title="">home</a></li>
                <li><a &lt;?php if($this->uri->segment(1) =='about'){echo "id='current'";}?&gt; href="about" title="">about</a></li>
                <li><a href="" title="">services</a></li>
                <li><a href="" title="">work</a></li>
                <li><a href="" title="">contact</a></li>
            </ol>

what do you guys think?
#7

[eluser]esra[/eluser]
[quote author="Rick Jolly" date="1190593867"]Maybe you'd be better to assign a "page" variable in the controller. The reason is that the controller knows what view it is loading. Using the uri segments isn't reliable because of the transparent routing that CI does when, for example, there is no controller specified in the uri, or some custom routes have been added to routes.php. Then you could do this:
Code:
<ol>
<li id="&lt;?php echo (('home' == $page): 'current' ? 'unselected'); ?&gt;"><a href="home" title="">home</a></li>
<li id="&lt;?php echo (('about' == $page): 'current' ? 'unselected'); ?&gt;"><a href="about" title="">about</a></li>
...
</ol>
[/quote]

Another good solution that I use for my own breadcrumbs pathway. I'm wondering if this should be standard config option, allowing variable replacement to be used in routes.php to automatically assign the default controller.




Theme © iAndrew 2016 - Forum software by © MyBB