Hey all,
I’ve got my Radiant shell up and running and I’m trying to figure things
out. One thing I’ve run across is building a menu and highlighting the
current page. Here’s what I have right now. It works but it’s really
really messy. I guess I could put it into a snippet or something but it
still seems like the hard way to do it. I looked at the <r:navigation>
stuff but I think that just works with children pages, correct?
<r:if_url matches="^/products"><li id="current"><a
href="/products">Products</r:if_url>
<r:unless_url matches="^/products">
Products</r:unless_url>
… etc …
Basically, I’m trying to single out the current page so that I can apply
a
CSS id to it. That id causes the menu item to be bold and give you the
feeling that your really on the page.
I know it’s probably something really stupid, but instead of messing
with it
for 3 days I thought I would ask you guys for some help.
Thanx!
Richard
BTW: The page I’m working on is at http://mail.kangaroobox.com:3000/.
Don’t
abuse me too much. 
I used to recommend the <r:navigation> tag, but nowadays, I’m thinking
body-ids combined with some dynamic CSS might work best. I might do
something like this in the layout:
Then in a separate (Radiant-stored) stylesheet, I would do something
like this:
<r:find url="/">
<r:snippet name=“page_menu_highlight” />
</r:find>
Then in the snippet named “page_menu_highlight”:
#page_<r:id/> #link_to_<r:id/> { font-weight: bold; } // or whatever
you want to use to highlight.
<r:children:each>
<r:snippet name=“page_menu_highlight” />
</r:children:each>
Then when generating your menu items, set the id on each item to
#link_to_<r:id/>.
If you have pretty much static menu options, <r:navigation/> is
arguably better, however.
Sean
Sean,
Thats good information. Since I will be having mostly static menu items
I’m
thinking that <r:navigation> might work better. However, I don’t really
know how to implement it for pages that don’t have a parent/child
relationship. All the samples seem to focus on dynamic menus built on
multiple levels of related pages. Or maybe I’m looking at them wrong…
Do
you have any hints/tips on using it?
Anyway, my major focus is going to be simplicity and efficiency. I
don’t
want to put up a huge boatload of processor intensive code just to build
a
menu. 
Later…
Richard
Woo Hoo! I think I’ve figured it out. I have it working in all cases
except the root “/” site (Home Page). Since every URL contains a ‘/’
my
‘Home’ page gets selected every time. Hmmmm…I see that the
<r:navigation> source shows that it can do RegExp processing but I’m not
sure how to turn it on. I LOVE open source code, but my Ruby reading
abilities are pretty weak.
Thanx!
Richard
Richard,
I usually put the home page in a separate case, outside the
<r:navigation>. That way, they won’t all be highlighted. Something
like this:
<li class="active"
Home
Ruby regexps’ literal syntax is basically the same as Perl regexps, if
that helps.
Sean