# Recursive \<children:each\>

**URL:** <https://www.ruby-forum.com/t/recursive-children-each/68682>\
**Category:** Radiant CMS\
**Created:** [September 14, 2006, 2:35pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682 "2006-09-14T14:35:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 2:35pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/1 "2006-09-14T14:35:51Z")

</div>

I wanted to generate a sitemap for my radiant powered site and used this  
code:

- 

Unfortunately it doesn’t work since r:children\_each is non recursive.  
Anyone  
has an idea on how to make it recursive?

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/2 "2006-09-14T14:45:51Z")

</div>

Giovanni -

I would first create a global tag, using any one of the methods  
previously  
discussed on the mailing list. The tag would be defined like so:

tag “if\_children” do |tag|  
tag.expand if tag.locals.page.has\_children?  
end

Then I would create a snippet that is similar to yours called “sitemap”:

\<r:children:each\>

- 

In the page that I want the sitemap I would do this (the find tag is  
optional, depending on where you want the sitemap to start):  
\<r:find url="/\>

Good luck!

Sean C.  
[seancribbs.com](http://seancribbs.com)

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/3 "2006-09-14T14:59:53Z")

</div>

Thanks, that kind of recursion what was I looking for. Actually you  
don’t  
even need the if\_children tag since \<r:children:each\> won’t execute if  
there  
are no children.

2006/9/14, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/4 "2006-09-14T15:13:54Z")

</div>

This is the final code I used.

In the sitemap page:

The sitemapper snippet:

\<r:children:each\>  
\<r:unless\_content part=“no-map”\>

-   
\<r:link /\>  

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

  
  
\</r:unless\_content\>  
\</r:children:each\>

2006/9/14, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 6:15pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/5 "2006-09-14T18:15:24Z")

</div>

On 14/09/06, Giovanni I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is the final code I used.

Thanks for posting this!

I’ve updated the wiki’s HowTo section with a ‘Recipies’ section, as  
discussed on list last week, and made this the first one! 🙂

[http://dev.radiantcms.org/radiant/wiki/HowToMakeASiteMap](http://dev.radiantcms.org/radiant/wiki/HowToMakeASiteMap)

The only significant change is that I made use of

\<r:children:each by=“title” order=“asc”\>

as otherwise the sitemap is ordered by Radiant’s page id numbers so  
the first page in the sitelist is the first page created

–  
Regards,  
Dave

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/6 "2006-09-14T18:16:55Z")

</div>

2006/9/14, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On 14/09/06, Giovanni I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > This is the final code I used.
> 
> Thanks for posting this!
> 
> I’ve updated the wiki’s HowTo section with a ‘Recipies’ section, as  
> discussed on list last week, and made this the first one! 🙂
> 
> [http://dev.radiantcms.org/radiant/wiki/HowToMakeASiteMap](http://dev.radiantcms.org/radiant/wiki/HowToMakeASiteMap)

Well it’s a honor to be the first there 🙂

> The only significant change is that I made use of

> \<r:children:each by=“title” order=“asc”\>
> 
> as otherwise the sitemap is ordered by Radiant’s page id numbers so  
> the first page in the sitelist is the first page created

I was sure I was using by=“title” 🙂

– Giovanni

---

<div class="post-metadata">

**Author:** ![Giovanni\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4491bb/32.png) [@Giovanni\_I](https://www.ruby-forum.com/u/Giovanni_I)\
**Post date:** [September 14, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/recursive-children-each/68682/7 "2006-09-14T18:16:55Z")

</div>

Nicely done, Giovanni and Dave.

Sean C.  
[seancribbs.com](http://seancribbs.com)
