getCollectionPath() for 1st and subsequent levels
Permalink
It was suggested that I hard code my main nav because the design and functionality is really complicated, so I put my main navigation in navigation_menu.php and am using <?php $this->inc('elements/navigation_menu.php'); ?> in header.php to include it. This is what some of the markup looks like in navigation_menu.php:
Works great. The CSS for "selected" shows up when the user is on that page.
Now I have a sublevel of navigation (actually two, but for simplicity's sake I'll say one). When I use the same setup as above on the second level, the CSS for that level shows the "selected" attribute, but then the one for the main navigation "selected" disappears.
Obviously that's because
is a main page, and
is a subpage.
But I can't figure out a way to have both the main nav and the sub nav selected when on a second level. Any help would be great.
<li class="single <?php echo ($c->getCollectionPath() == '/about') ? 'selected' : ''; ?>"> <a href="about">About Us</a> </li>
Works great. The CSS for "selected" shows up when the user is on that page.
Now I have a sublevel of navigation (actually two, but for simplicity's sake I'll say one). When I use the same setup as above on the second level, the CSS for that level shows the "selected" attribute, but then the one for the main navigation "selected" disappears.
Obviously that's because
($c->getCollectionPath() == '/about')
is a main page, and
($c->getCollectionPath() == '/about/subpage')
is a subpage.
But I can't figure out a way to have both the main nav and the sub nav selected when on a second level. Any help would be great.
Yup, you can use the View::section() function, like this:
<?php if (View::section('/about')) { //The current page is somewhere under the "about" page } else { //The current page is *not* under the "about" page } ?>
Unfortunately it's not working. I know I'm doing something wrong. I have this:
Any suggestions?
<li class="single <?php if (View::section('/about')) { print 'selected'; } else { } ?>"> <a href="/about">About</a> </li>
Any suggestions?
Nevermind, got it! Just had to get rid of the forward slash.
Thanks so much!! Works great.
<?php if (View::section('about')) { print 'selected'; } else { } ?>
Thanks so much!! Works great.
and it worked. But is there a better way?