# Children:each vs. navigation

**URL:** <https://www.ruby-forum.com/t/children-each-vs-navigation/71687>\
**Category:** Radiant CMS\
**Created:** [October 10, 2006, 8:56pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687 "2006-10-10T20:56:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 10, 2006, 8:56pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/1 "2006-10-10T20:56:47Z")

</div>

Hi,

I’m building a site in radiant that has a section with a long  
subnavigation  
menu. Initially I built it like this:

\<r:find url="/section/papers/"\>  
\<r:children:each by=“title”\>

  

### \<r:link /\>
  

\<r:content part=“shortline” /\>

  

  
\</r:children:each\>  
\</r:find\>

That works fine, except that I need selected behaviour like r:navigation  
has  
so that I can add another class to the div class=entry to highlight the  
sub  
page the user is on.

I’ve tried using a big & nasty r:navigation tag (its a long list), but  
the  
problem in that case are the r:link & r:content bits referring to the  
current page rather than the page I’m creating a link.

Is there any way to accomplish this with the basic tag set in radiant? I  
can  
imagine a few ways to modify the r:navigation or r:children:each tag  
definitions, but that doesn’t really seem like a great way to go to me.  
Am I  
missing something obvious here?

Thanks,  
Jim

---

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 20, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/2 "2006-10-20T22:46:43Z")

</div>

Jim Herring wrote:

> Hi,
> 
> I’m building a site in radiant that has a section with a long  
> subnavigation  
> menu. Initially I built it like this:
> 
> \<r:find url="/section/papers/"\>  
> \<r:children:each by=“title”\>
> 
>   
> 
> ### \<r:link /\>
>   
> 
> \<r:content part=“shortline” /\>
> 
>   
> 
>   
> \</r:children:each\>  
> \</r:find\>
> 
> That works fine, except that I need selected behaviour like r:navigation  
> has  
> so that I can add another class to the div class=entry to highlight the  
> sub  
> page the user is on.
> 
> I’ve tried using a big & nasty r:navigation tag (its a long list), but  
> the  
> problem in that case are the r:link & r:content bits referring to the  
> current page rather than the page I’m creating a link.
> 
> Is there any way to accomplish this with the basic tag set in radiant? I  
> can  
> imagine a few ways to modify the r:navigation or r:children:each tag  
> definitions, but that doesn’t really seem like a great way to go to me.  
> Am I  
> missing something obvious here?
> 
> Thanks,  
> Jim

Jim,

I’ve read your message a couple times and don’t fully understand your  
question.

This part in particualr is where I’m losing you:

> the problem in that case are the r:link & r:content bits referring to  
> the current page rather than the page I’m creating a link.

Can you clarify this part and I might be able to help. I’m currently  
implementing a site in Radiant which is requiring plent of  
\<r:navigation… tags and is crying for some more automated options that  
still have some r:navigation style “selected” and “here” class tagging.

I’ve had good success creating some global tags and am working on a  
couple of behaviors. Perhaps if I can understand what you’re after we  
could collaborate on a new tag or two to meet both our needs.

Loren

---

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 23, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/3 "2006-10-23T19:47:42Z")

</div>

Hi Loren,

I ended up solving this particular problem a different way, but the  
original  
issue is still a pain.

This part in particualr is where I’m losing you:

> > the problem in that case are the r:link & r:content bits referring to  
> > the current page rather than the page I’m creating a link.
> 
> Can you clarify this part and I might be able to help. I’m currently  
> implementing a site in Radiant which is requiring plent of  
> \<r:navigation… tags and is crying for some more automated options that  
> still have some r:navigation style “selected” and “here” class tagging.

Here is (I hope) a lucid description. What I found is that inside an  
r:children:each tag, one has full access to each child’s data: title,  
url,  
link, slug, content, etc. The drawback with r:children:each is that the  
ability to order and filter the child is, errr, rather primative. 🙂

The navigation tag on the other hand allows complete manual control over  
the  
items looped over. The drawback is that inside a navigation tag one  
doesn’t  
actually have access to the pages being referred to. For example, here  
is a  
simple nav component for doodads. /doodads/ is the main doodad page, and  
it  
has perhaps 10 children, each of which is a different doodad detail page  
(doodad-1, doodad-2, … doodad-n). The component is meant to be shown  
on  
the doodad overview and detail pages, and should highlight the doodad  
page  
we are on, if we are on a doodad detail page.

### 

### 

This works great as a snippet with one huge exception- the \<r:content\>  
tags  
refer to whatever page the user is looking at, not to the urls fed in by  
the  
navigation tag. I was wrong about the link tag not working here, it  
does.

I ended up solving the problem using children:each and some css to get  
around the lack of normal/here/selected tags. By setting the pages body  
id="\<r:slug /\>" and the div.item ids to each doodad’s r:slug it became  
easy  
to write CSS to “activate” any div.item whose id == body’s id.

 body# #doodad-selector .item# { background-color: #ffc } body# #doodad-selector .item# h3 { color: #333 } 

### Doodad Nav

```
<r:children:each by="title">
  <r:link><div class="item" id="<r:slug />">
      <h3><r:title /></h3><r:content part="navline" /></div>
  </r:link>
</r:children:each>

```

\</r:find\>

That worked well for my purposes, but I would still love to have a  
navigation tag that refers to actual pages rather than title/url pairs.  
Or  
maybe better would be an \<r:foreach\> tag which operates on a list of  
pages  
or the children of some page, and allows here / selected matching  
inside.

All in all though Radiant has offered elegant solutions for most aspects  
of  
the site I’m building.

Jim

---

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 27, 2006, 9:28pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/4 "2006-10-27T21:28:19Z")

</div>

I want to organize old writings from the 1950s and sort them as articles  
by date. I want to use a new content part titled ansi\_date (19560417).  
Is  
there a way to sort the articles by my ansi\_date content part using the  
\<r:children:each\> tag?

---

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 28, 2006, 1:30am UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/5 "2006-10-28T01:30:46Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I want to organize old writings from the 1950s and sort them as articles  
> by date. I want to use a new content part titled ansi\_date (19560417). Is  
> there a way to sort the articles by my ansi\_date content part using the  
> \<r:children:each\> tag?

Probably the best thing would be to manually update the articles  
published\_at date over the console or to write a script to do this for  
you. The published\_at field is the default order by field.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![Jim\_Herring](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@Jim\_Herring](https://www.ruby-forum.com/u/Jim_Herring)\
**Post date:** [October 28, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/children-each-vs-navigation/71687/6 "2006-10-28T16:49:30Z")

</div>

Thanks for the attention John.

Being able to sort pages by content part would be a great feature. I’m  
just starting with this so I’ve no clue on how to pull off something  
like  
that. But I’ll do what you’ve recommended.

Jose.
