# Parse and render radius within a tag

**URL:** <https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687>\
**Category:** Radiant CMS\
**Created:** [August 22, 2007, 4:57am UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687 "2007-08-22T04:57:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 4:57am UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/1 "2007-08-22T04:57:51Z")

</div>

Hello,

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.

Steve

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/2 "2007-08-22T13:53:53Z")

</div>

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 

```

developer  
point of view:

```
http://radius.rubyforge.org/files/QUICKSTART.html

 /AITOR
```

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/3 "2007-08-22T14:10:18Z")

</div>

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.

Steve

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 2:57pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/4 "2007-08-22T14:57:15Z")

</div>

> 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 

```

of  
expanding the tag and accumulating the result:

[http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard\_tags.rb#L88](http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard_tags.rb#L88)

```
 <random> is also nice simple example:

```

[http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard\_tags.rb#L431](http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard_tags.rb#L431)

```
  /AITOR

```

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/5 "2007-08-22T21:59:05Z")

</div>

OK, now i see the problem, the data is in the database.

```
In this case the code you posted before is the way to go. But 

```

instead  
of creating a new context i would suggest using the context you  
inherited  
from the tag.

```
The API docs say that the context is "tag.context", but also notes 

```

“The  
Context [http://radius.rubyforge.org/classes/Radius/Context.html](http://radius.rubyforge.org/classes/Radius/Context.html) that  
the  
TagBinding [http://radius.rubyforge.org/classes/Radius/TagBinding.html](http://radius.rubyforge.org/classes/Radius/TagBinding.html)  
is  
associated with. Used internally. Try not to use this object directly.”

```
 /AITOR

```

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/6 "2007-08-22T16:41:40Z")

</div>

Aitor,

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.

Steve

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 24, 2007, 3:18am UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/7 "2007-08-24T03:18:09Z")

</div>

I just thought I would report back and say that this ended up working  
great. If anybody else needs to do this here’s the code I’m using

tag “event:body” do |tag|  
parser = Radius::Parser.new(tag.context, :tag\_prefix =\> ‘r’)  
parser.parse(tag.locals.event.body)  
end

Thanks aitor for your help.

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 22, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/8 "2007-08-22T22:16:13Z")

</div>

Perfect. tag.context That’s exactly what I was looking for. I’ll try  
it when I get home tonight and see if it works. Thanks for the help.

Steve

---

<div class="post-metadata">

**Author:** ![stenzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@stenzer](https://www.ruby-forum.com/u/stenzer)\
**Post date:** [August 24, 2007, 4:31am UTC](https://www.ruby-forum.com/t/parse-and-render-radius-within-a-tag/112687/9 "2007-08-24T04:31:33Z")

</div>

Steve E. wrote:

> I just thought I would report back and say that this ended up working  
> great. If anybody else needs to do this here’s the code I’m using
> 
> tag “event:body” do |tag|  
> parser = Radius::Parser.new(tag.context, :tag\_prefix =\> ‘r’)  
> parser.parse(tag.locals.event.body)  
> end
> 
> Thanks aitor for your help.

You might also be able to use Page#render\_snippet in a way that is  
similar to the snippet tag:

[http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard\_tags.rb#L389](http://dev.radiantcms.org/radiant/browser/trunk/radiant/app/models/standard_tags.rb#L389)

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)
