First of all, let me say that I’m liking the extension system. It seems
to work pretty well for adding little bits of functionality. One of the
extensions that I’ve been working on is an events calendar. My event
table has a “body” field where the user can type a long description
about the event. I would like for them to be able to use some radius
tags within that field. In other words, within my definition of the
“event:body” tag I would like to be able to parse the text for any
radius tags and have them rendered appropriately. Is there an easy way
to get at Radiant’s radius context and parser from within a tag
definition? Or do I need to instantiate my own radius context and
parser? If I have to instantiate my own, is there an easy way for me to
use tags that have already defined in radiant? Sorry if all of this is
confusing. Just curious if anybody else has run into something similar.
I don’t understand well what you mean. I believe that you want
something like:
<event>
<date date="..." />
<title> .... </title>
<body>
.....
</body>
</event>
And be able to "parse" the sub-tags an do something useful with
that.
I don't believe that it's easy to do your own parsing with Radius,
maybe it’s not even possible. But that does not matter. IMHO, the way
to
handle this is to expand the tag, which will expand the
sub-tags.
In the sub-tags you bind data to the tag, so when the expanding
ends
at the tag it has all the information and can render whatever
HTML
you want and return it.
The point here is to realize that expanding a tag does not mean
that
you have to return the HTML you get back, you can return whatever you
want.
In the case explained above, the sub-tags will not even return any HTML,
just add data to the parent tag.
I found this doc nice for understanding the Radius tags from a
Thanks Aitor. I probably wasn’t very clear in my first post. Sorry
about that. Let me see if I can explain it again.
I already have <r:event></r:event>, <r:event:date format="" />,
<r:event:title />, <r:event:body />. The problem is that the text in my
body tag also contains radius content. For example, I wanted to define
a radius tag for creating links, or creating an inline google map or
some simple formatting. In order to let my users be able to use radius
tags in the “body” field of my event in a similar manner as the body
field of a page, I need to have some way of parsing the body text. One
of the things I was considering doing was just creating my own radius
context and parser. The body tag definition would then look something
like the following (psuedo-code)
tag “event:body” do |tag|
context = Radius::Context.new()
parser = Radius::Parser(context, :tag_prefix => ‘r’) #some code to define tags
parser.parse(tag.locals.event.body)
end
I was trying to avoid creating my own context and parser and instead use
the already existing one that Radiant uses. that would I wouldn’t have
to figure out how to redefine all of the existing page tags, but maybe
I’ll just end up going down that route.
In order to let my users be able to use radius
tags in the “body” field of my event in a similar manner as the
body
field of a page, I need to have some way of parsing the body text.
You don't need to do any parsing. If you expand the <r:event:body>
tag, Radius will take care of rendering whatever is inside, including
any
other tag. Then you get the result in the <r:event> tag and do whatever
you
want.
This will not work if you want some kind of fine control on how the
tags inside <r:event:body> expand, but as i understand this is not what
you
are looking for.
Take a look to the code of the <children:each> tag for an example
I believe what you’re suggesting would work if the body text was
actually stored on the Page. The problem is that the body text for the
event isn’t stored on the page. It is stored in the body field of the
event table. As a result, when that text gets included in a page (via
the <r:event:body /> tag), the radius tags used in the text event.body
field will simply be treated as plain text.