# Newb Menu Question

**URL:** <https://www.ruby-forum.com/t/newb-menu-question/115513>\
**Category:** Radiant CMS\
**Created:** [September 25, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/newb-menu-question/115513 "2007-09-25T22:04:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardchaven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@richardchaven](https://www.ruby-forum.com/u/richardchaven)\
**Post date:** [September 25, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/newb-menu-question/115513/1 "2007-09-25T22:04:18Z")

</div>

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?

- Home
- Home
 

```
<r:if_url matches="^/products"><li id="current"><a

```

 

href=“/products”\>Products\</r:if\_url\>  
\<r:unless\_url matches=“^/products”\>

- [Products](https://www.ruby-forum.com/products)
[\</r:unless\_url\>

 

… etc …

 ](https://www.ruby-forum.com/products)
[](https://www.ruby-forum.com/products)
[ 

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

 ](https://www.ruby-forum.com/products)

[BTW: The page I’m working on is at](https://www.ruby-forum.com/products)[http://mail.kangaroobox.com:3000/](http://mail.kangaroobox.com:3000/).  
Don’t  
abuse me too much. 🙂

---

<div class="post-metadata">

**Author:** ![richardchaven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@richardchaven](https://www.ruby-forum.com/u/richardchaven)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/newb-menu-question/115513/2 "2007-09-25T23:10:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richardchaven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@richardchaven](https://www.ruby-forum.com/u/richardchaven)\
**Post date:** [September 26, 2007, 1:53am UTC](https://www.ruby-forum.com/t/newb-menu-question/115513/3 "2007-09-26T01:53:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richardchaven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@richardchaven](https://www.ruby-forum.com/u/richardchaven)\
**Post date:** [September 26, 2007, 2:25am UTC](https://www.ruby-forum.com/t/newb-menu-question/115513/4 "2007-09-26T02:25:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richardchaven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@richardchaven](https://www.ruby-forum.com/u/richardchaven)\
**Post date:** [September 26, 2007, 4:31am UTC](https://www.ruby-forum.com/t/newb-menu-question/115513/5 "2007-09-26T04:31:59Z")

</div>

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
