# Accessing the tags of children from within an each

**URL:** <https://www.ruby-forum.com/t/accessing-the-tags-of-children-from-within-an-each/64122>\
**Category:** Radiant CMS\
**Created:** [June 22, 2006, 9:04am UTC](https://www.ruby-forum.com/t/accessing-the-tags-of-children-from-within-an-each/64122 "2006-06-22T09:04:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dasch](https://www.ruby-forum.com/u/dasch)\
**Post date:** [June 22, 2006, 9:04am UTC](https://www.ruby-forum.com/t/accessing-the-tags-of-children-from-within-an-each/64122/1 "2006-06-22T09:04:43Z")

</div>

To go along with my changes to have different type of pages, I change  
the definition of \<r:title\>,\<r:url\>, etc… that it calls a new method  
on @page, “tag\_attributes” to get the list of available methods  
(previously it used @page.attributes.symbolize\_keys.keys) so that new  
page models could expose more things for tags. I also changed the  
unless\_url/if\_url tags so that there was a corresponding unless/if for  
each attribute.

However, this doesn’t work quite the way I’d like. I can’t do this:

\<r:children:each:child\>  
\<r:if\_type matches=“FileAsset”\>  
\<r:if\_content\_type matches="^image"\>  
\<r:image /\>  
\</r:if\_content\_type\>  
\</r:if\_type\>  
\</r:children:each:child\>

(there will be a better way to get all child images of a page, I just  
haven’t thought of it yet, so this is the first principles process).

Because tags are defined by the currently rendering page, and  
if\_content\_type has no meaning here (the @page in question is a regular  
page, and knows nothing of content\_type).

Would it make sense to basically switch context completely while within  
a children:each:child tag to delegate all tags to the child page? Does  
this clash with the fundamental architecture of radius. In this case, I  
can work around this by introducing an “\<r:attribute\>” tag that does the  
same thing (with corresponding \<r:unless\_attribute\> and \<r:if\_attribute\>  
tags), but thought I might raise this in case anybody can think of other  
types of tags/behaviours that might be hindered by this.

And while you’ve got the example above fresh in your mind - doing a  
children:each:child with conditions… how would you like to see it  
done?

if would be simple enough to add on:

\<children:each:child type=“image”\>  
\<children:each:child type=“file”\>  
\<children:each:child type=“page”\>

but what if you want to, say, only grab children by a certain author? by  
some other attribute? what if you want to grab all non-page, non-image  
children? Maybe, once again I’m just thinking too hard about things that  
are above and beyond what a CMS should be doing, because I don’t really  
see a way to do everything that I can think of without throwing in an  
ErbBehaviour (which, looks to be dead simple if it comes to that).

---

<div class="post-metadata">

**Author:** ![dasch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b2d939/32.png) [@dasch](https://www.ruby-forum.com/u/dasch)\
**Post date:** [June 22, 2006, 4:40pm UTC](https://www.ruby-forum.com/t/accessing-the-tags-of-children-from-within-an-each/64122/2 "2006-06-22T16:40:49Z")

</div>

Daniel S. wrote:

> types of tags/behaviours that might be hindered by this.  
> That is a very interesting question. I tend to think that it would be a  
> bad idea to switch to the other page’s context inside the  
> \<r:children:each /\> block. The reason being is that you can still use  
> the parent page’s tags inside the child each block, and I would want the  
> parent’s tags to have precedence over the child’s. (Incidentally, if you  
> ever want to get back to the parent pages attributes inside the child  
> each block you can use the \<r:page /\> tag.)

I’d recommend adding a tag that allows you to do what you want. An  
if\_image tag, or something of that nature.

> but what if you want to, say, only grab children by a certain author? by  
> some other attribute? what if you want to grab all non-page, non-image  
> children? Maybe, once again I’m just thinking too hard about things that  
> are above and beyond what a CMS should be doing, because I don’t really  
> see a way to do everything that I can think of without throwing in an  
> ErbBehaviour (which, looks to be dead simple if it comes to that).

I think I’d recommend adding a custom attribute like “type” as you  
suggested. You could also create a custom tag like  
\<r:attachments:each /\> or something of that nature.

–  
John
