# Submenu

**URL:** <https://www.ruby-forum.com/t/submenu/69004>\
**Category:** Radiant CMS\
**Created:** [September 18, 2006, 3:47am UTC](https://www.ruby-forum.com/t/submenu/69004 "2006-09-18T03:47:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 3:47am UTC](https://www.ruby-forum.com/t/submenu/69004/1 "2006-09-18T03:47:52Z")

</div>

I don’t know if anyone is currently working on or will be adding a kind  
of menu functionality to Radiant. The idea being that there are  
navigational element necessary to navigate the site’s content areas.

The idea here is that for content, it automatically creates a

 list  
that you can manipulate to your liking.

So:

/ – root

  - — Home
  - — About Me  
------- About the Site
  - — Database  
------- Sub Section One  
--------- Page One  
--------- Page Two  
------------ Sub Page One
  - — Contact Me

This would be automatically created inside a tag, possibly something  
like \<r:menu /\> which would have options to exclude pages and etc and  
style to your liking, so only page relevant to the area show up.

I hope I am getting my idea across.

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 4:20am UTC](https://www.ruby-forum.com/t/submenu/69004/2 "2006-09-18T04:20:58Z")

</div>

Ian G. wrote:

> I don’t know if anyone is currently working on or will be adding a kind  
> of menu functionality to Radiant. The idea being that there are  
> navigational element necessary to navigate the site’s content areas.
> 
> The idea here is that for content, it automatically creates a
> 
> list  
> that you can manipulate to your liking.
> 
> So:
> 
> / – root
> 
> - — Home
> - — About Me  
> ------- About the Site
> - — Database  
> ------- Sub Section One  
> --------- Page One  
> --------- Page Two  
> ------------ Sub Page One
> - — Contact Me
> 
> This would be automatically created inside a tag, possibly something  
> like \<r:menu /\> which would have options to exclude pages and etc and  
> style to your liking, so only page relevant to the area show up.
> 
> I hope I am getting my idea across.

I am in need of something very similar to this and will probably be  
tackling the problem sometime in the week. Have you looked at the  
sitemap howto? That may be a good place to start.

Seancribbs also showed some interest in producing such a tag in IRC the  
other day although I’m not sure if anything came from that in the end.

Kev

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 4:34am UTC](https://www.ruby-forum.com/t/submenu/69004/3 "2006-09-18T04:34:49Z")

</div>

On Sep 18, 2006, at 11:20 AM, Kevin A. wrote:

> Ian G. wrote:
> 
> > I don’t know if anyone is currently working on or will be adding a  
> > kind  
> > of menu functionality to Radiant. The idea being that there are  
> > navigational element necessary to navigate the site’s content areas.

> I am in need of something very similar to this and will probably be  
> tackling the problem sometime in the week. Have you looked at the  
> sitemap howto? That may be a good place to start.

I’ve thought about doing something similar, but I just haven’t had  
the time to get to it. I was thinking to make a tag very similar to  
the \<r:navigation /\> tag, but instead of giving it a list of titles  
and paths, give it a parent page, eg:

\<r:menu parent="/root/path" /\>

and it uses the \<r:selected /\> and other navigation tags.

Nothing but talk to show for it yet though… 🙂

Bodhi

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 5:53am UTC](https://www.ruby-forum.com/t/submenu/69004/4 "2006-09-18T05:53:18Z")

</div>

I think we should get some code posted and people might be more apt to  
try and do something. Hmm, code, damn my newbie skills with ruby!

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 11:50am UTC](https://www.ruby-forum.com/t/submenu/69004/5 "2006-09-18T11:50:06Z")

</div>

Bodhi wrote:

> I’ve thought about doing something similar, but I just haven’t had  
> the time to get to it. I was thinking to make a tag very similar to  
> the \<r:navigation /\> tag, but instead of giving it a list of titles  
> and paths, give it a parent page, eg:
> 
> \<r:menu parent="/root/path" /\>
> 
> and it uses the \<r:selected /\> and other navigation tags.

Hmm, that’s another possibility. I may try to tackle this today if I can  
get my head around how to best deal with the multiple levels and  
expanding the current section correctly.

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 6:01am UTC](https://www.ruby-forum.com/t/submenu/69004/6 "2006-09-18T06:01:31Z")

</div>

Here is an attempt at it.

submenu\_behavior.rb

class SubMenuBehavior \< Behavior::Base

register “Sub Menu”

description %{  
Submenu is the ability for pages to have their parent and children  
automatically generated into

's for users.  
}

define\_tags do  
tag ‘submenu’ do  
‘Create list’  
end

tag ‘submenu’ do |tag|  
name = tag.attr[‘exclude’] || ‘array’  
…  
exclude code here  
…  
end

end

I don’t even know ruby that well so this is all probably terribly wrong,  
you can laugh if you want :\*-(

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 1:13pm UTC](https://www.ruby-forum.com/t/submenu/69004/7 "2006-09-18T13:13:32Z")

</div>

On our website, I implemented submenus the following way:

1. Create a submenu snippet:

- 

This renders an unordered list of links to all children of a page. If  
some pages are to be excluded, you can do this by adding some  
\<r:unless\_url/\> markup.

1. Create a content part “submenu” on each first levelpage that has  
children:

\<r:find url=“page\_name”\>  
\<r:snippet name=“submenu”/\>  
\</r:find\>

This calls the above snippet with the current page selected so that the  
snippet will iterate over its children and render its submenu.

1. Include the content part in your layout

\<r:content part=“submenu” inherit=“true”/\>

The “inherit” attribute makes sure the submenu will be used on all child  
pages unless overridden.

It’s a quick and rather non-DRY solution because you have to define the  
content part on each first level page and to manually enter the page  
title there, but from there everything works automatically. Highlighting  
etc. can be done with CSS - if you are interested, I can post some code.

Hope you can use it!

Cheers,  
Wolfgang

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 1:47pm UTC](https://www.ruby-forum.com/t/submenu/69004/8 "2006-09-18T13:47:37Z")

</div>

Hi,

I have 2 snippets for my navigation.

1. Primary Navigation:

- 8\< –

 ![UKTUG](https://www.ruby-forum.com/images/uktug/texlogo_50.png)

## Site Navigation

- Home
- [Membership](https://www.ruby-forum.com/membership)
- [Events](https://www.ruby-forum.com/events)
- [Resources](https://www.ruby-forum.com/resources)
- [Constitution](https://www.ruby-forum.com/constitution)
- [Baskerville](https://www.ruby-forum.com/baskerville)
- [Contact](https://www.ruby-forum.com/contact)
- [About](https://www.ruby-forum.com/about)

![Masthead Image of a Lion, the TeX mascot](https://www.ruby-forum.com/images/uktug/lions/100/grey/<r:random>%20<r:option>grey</r:option>%20<r:option>mgm</r:option>%20<r:option>mow</r:option>%20<r:option>sculpture</r:option>%20<r:option>grass</r:option>%20<r:option>bronze</r:option>%20<r:option>iron</r:option>%20<r:option>holborn</r:option>%20<r:option>dollar</r:option>%20<r:option>photo</r:option>%20<r:option>fairmount</r:option>%20<r:option>eye</r:option>%20<r:option>dayglo</r:option>%20<r:option>sand</r:option>%20<r:option>hsbc</r:option>%20<r:option>green</r:option>%20<r:option>boston</r:option>%20<r:option>egypt</r:option>%20<r:option>door</r:option>%20<r:option>china</r:option>%20</r:random>_100.jpg)  
– 8\< –

1. SecondaryNavigation  
– 8\< –

## Breadcrumbs

## Child Pages

- 
- → 

And then this ‘Normal’ Layout:  
– 8\< –

\<r:snippet name=“secondarynavigation” /\>

* * *

# 

* * *

-- 8\< --

Note the smart way of including page-level CSS by just creating a  
‘stylesheet’ Page Part in the Admin Interface, but if no part of that  
name exists then the page does now show any signs of it. (Just added  
to Receipes on Wiki 🙂

I also want to follow the \<r:if\_child\> to the secondarynavigation so  
instead of

## Child Pages

- 
- → 

I can do

## Child Pages

- → 

But not had time yet 🙂

–  
Regards,  
Dave

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 18, 2006, 1:47pm UTC](https://www.ruby-forum.com/t/submenu/69004/9 "2006-09-18T13:47:37Z")

</div>

On 18/09/06, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I have 2 snippets for my navigation.

See this in action at [http://uk.tug.org](http://uk.tug.org) 🙂

–  
Regards,  
Dave

---

<div class="post-metadata">

**Author:** ![dzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dzo](https://www.ruby-forum.com/u/dzo)\
**Post date:** [September 19, 2006, 6:58am UTC](https://www.ruby-forum.com/t/submenu/69004/10 "2006-09-19T06:58:51Z")

</div>

Dave C. wrote:

> On 18/09/06, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,
> > 
> > I have 2 snippets for my navigation.
> 
> See this in action at [http://uk.tug.org](http://uk.tug.org) 🙂
> 
> –  
> Regards,  
> Dave

Thanks Dave I will definately give it a try and see how I can improve on  
it, if I can.
