# Radius Evaluation Context

**URL:** <https://www.ruby-forum.com/t/radius-evaluation-context/90870>\
**Category:** Radiant CMS\
**Created:** [April 2, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/radius-evaluation-context/90870 "2007-04-02T16:52:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ol1barn3s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de053/32.png) [@ol1barn3s](https://www.ruby-forum.com/u/ol1barn3s)\
**Post date:** [April 2, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/radius-evaluation-context/90870/1 "2007-04-02T16:52:42Z")

</div>

Hi all,

I guess this question is probably more directed to John, but I would  
like some discussion on this topic. If I understand it correctly all  
Radius tags in a page are currently evaluated within the same context,  
the context of that page. This, however, limits the number of  
available tags to those defined for that page and my question is  
whether it would be possible to change the context in which tags are  
being evaluated dynamically?

Consider the following example:

Page /:

\<r:find url="/archive/"\>  
\<r:children:each\>  
\<r:link/\>  
\</r:children:each\>  
\</r:find\>

Currently, all of these tags are evaluated in the context of page /. I  
am suggesting, however, to evaluate each tag in the local context it  
actually refers to. In this example \<r:children:each\> would be  
evaluated in the context of page /archive/ and \<r:link\> in the context  
of each of the respective children of /archive/.

You may now ask why that would be useful? The answer is quite simple:  
with different page types defined, a single context does not have the  
knowledge of the capabilities of each page type when it processes it.  
In the example above, we assume that page / knows how page /archive/  
stores its children, and how a link to any of these children is  
constructed. This, however, cannot always be assumed, as /archive/ may  
prefer to use a different algorithm to iterate over its children than /.

This approach also allows to limit tags to only those contexts in  
which they are useful. For example:

\<r:find “/gallery/”\>  
\<r:images:each\>  
\<r:thumbnail/\>  
\</r:images:each\>  
\</r:find\>

With the context dynamically changing there is no need to define the  
tags \<r:images:each\> and \<r:thumbnail\> globally as a standard page  
tag, but instead leave it restricted to the gallery page.

What do you think? I hope that made sense and wasn’t too confusing.

Cheers,  
Oliver

---

<div class="post-metadata">

**Author:** ![ol1barn3s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de053/32.png) [@ol1barn3s](https://www.ruby-forum.com/u/ol1barn3s)\
**Post date:** [April 2, 2007, 5:06pm UTC](https://www.ruby-forum.com/t/radius-evaluation-context/90870/2 "2007-04-02T17:06:44Z")

</div>

Put it in a snippet! Snippets are evaluated in the context of the  
local page (whether that’s the one being rendered on a global level or  
not).

However, I do see your point. I’m not sure what complications it  
would cause in the parsing/evaluating.

Sean

---

<div class="post-metadata">

**Author:** ![ol1barn3s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9de053/32.png) [@ol1barn3s](https://www.ruby-forum.com/u/ol1barn3s)\
**Post date:** [April 2, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/radius-evaluation-context/90870/3 "2007-04-02T17:34:46Z")

</div>

Hi Sean:

Sean C. wrote:

> Put it in a snippet! Snippets are evaluated in the context of the  
> local page (whether that’s the one being rendered on a global level or  
> not).

Yeah, I know I can include parts from other pages or snippets into the  
current page and the tags in those parts will be rendered in the  
context of the page they belong to. But I was more wondering about the  
case where you don’t know what type of page you are accessing. As in:

\<r:children:each\>

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

> However, I do see your point. I’m not sure what complications it  
> would cause in the parsing/evaluating.

It probably would have to be decided on a tag by tag basis whether to  
change the context or not and probably is something that is largely  
done in the tag implementation and not in Radius. E.g.:

tag ‘children:each’ do |tag|  
options = children\_find\_options(tag)  
result = []  
children = tag.locals.children  
tag.locals.previous\_headers = {}  
children.find(:all, options).each do |item|

- tag.locals.child = item
- tag.locals.page = item
- result \<\< tag.expand

- p = Radius::Parser.new(item.context, :tag\_prefix =\> ‘r’)
- result \<\< p.parse(tag.raw\_content)  
end  
result  
end

Though, I could not find anything in Radius that would be a equivalent  
to #raw\_content.

Cheers,  
Oliver
