# Navigation and Sub Menus

**URL:** <https://www.ruby-forum.com/t/navigation-and-sub-menus/64497>\
**Category:** Radiant CMS\
**Created:** [August 9, 2006, 3:52pm UTC](https://www.ruby-forum.com/t/navigation-and-sub-menus/64497 "2006-08-09T15:52:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [August 9, 2006, 3:52pm UTC](https://www.ruby-forum.com/t/navigation-and-sub-menus/64497/1 "2006-08-09T15:52:45Z")

</div>

Guys

I am so close to finishing my first radiant site. Just one last thing  
to do  
to get things finished. Each of the section in my website has a sub  
menu.  
Works wonderfully. However, my boss now wants to have further sub  
menus.  
Here’s the example:-

Who We Are  
Our Past  
Article One  
Article Two  
Our Present  
Our Future  
Our People  
Partners  
Managers

What my boss wants, is that if the user is in the Our People section or  
one  
of its children, the following would get shown.

Our Past  
Our Present  
Our Future  
Our People  
Partners  
Managers

I didn’t think it would be too difficult, so created code using the  
r:page:if\_url syntax as follows:-

\<r:find url="/who-we-are/"\>

# 

- 

\<r:page:if\_url matches="/our-people/"\>  
\<r:children:each\>

- \<r:title /\>
  
\</r:children:each\>  
\</r:page:if\_url\>  
\</r:children:each\> 

What this actually produces is

Our Past  
Partners  
Managers  
Our Present  
Partners  
Managers  
Our Future  
Partners  
Managers  
Our People  
Partners  
Managers

This is only displayed if you are viewing the Our People section. I  
have to  
be selective about which sections will have further subsections so can’t  
simply nest a children:each in another one. I am just having problems  
getting round what actually happening in each context.

Does anybody have any suggestions?

Thanks in advance  
Regards  
Harvey

This e-mail has been scanned for all viruses by MessageLabs.

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [August 9, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/navigation-and-sub-menus/64497/2 "2006-08-09T16:13:47Z")

</div>

If nobody has a more specific answer (I don’t have it), I do remember a  
similar question being asked here not so long ago. So you might be  
helped by the archives.

Regards,  
Erik.

Harvey B. schreef:

> ```
> Article Two
> 
> ```
> 
> Our Present
> 
> # 
> Partners simply nest a children:each in another one. I am just having problems \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Radiant mailing list removed\_email\_address@domain.invalid http://lists.radiantcms.org/mailman/listinfo/radiant

–  
Erik van Oosten

> **[Day to day stuff](http://day-to-day-stuff.blogspot.com/)**
>
> Experiences from a hard core JVM programmer. Likes to keep things simple.

---

<div class="post-metadata">

**Author:** ![Harvey\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/13edae/32.png) [@Harvey\_B](https://www.ruby-forum.com/u/Harvey_B)\
**Post date:** [August 10, 2006, 3:08am UTC](https://www.ruby-forum.com/t/navigation-and-sub-menus/64497/3 "2006-08-10T03:08:45Z")

</div>

On 09/08/2006, at 10:50 PM, Harvey B. wrote:

> Guys

> This is only displayed if you are viewing the Our People section. I  
> have to  
> be selective about which sections will have further subsections so  
> can’t  
> simply nest a children:each in another one. I am just having problems  
> getting round what actually happening in each context.
> 
> Does anybody have any suggestions?

I had the same problem, I ended up implementing two custom tags:

Behavior::Base.define\_child\_tags do  
tag ‘if\_current\_page’ do |tag|  
if tag.locals.page == tag.globals.page  
tag.expand  
end  
end

tag ‘if\_current\_parent’ do |tag|  
potential\_parent = tag.locals.page  
child = tag.globals.page  
if child.child\_of? potential\_parent  
tag.expand  
end  
end  
end

I also patched Page to add Page#child\_of? (used in  
\<r:if\_current\_parent\>) but you could do it inline.

Then in my navigation snippet I used these to conditionally show the  
children/siblings of the page in question…

For some reason I needed to use #define\_child\_tags rather than  
#define\_tags, as the custom tags wouldn’t be available in pages with a  
custom behaviour. John, if you read this, would you be able to take a  
second and explain why? (I couldn’t quite figure it out going through  
the code)

Bodhi
