Accessing the tags of children from within an each

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).

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs