Radius Evaluation Context

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

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

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