Sunday, January 14, 2007

How to build a simple Radius Tag

In RadiantCMS (CMS system written in Rails), developers use Radius Tag to render the view content instead of ActionView. Here's a small tips to generate your own tag.

to render a text:

define_tag 'hello' do |tag|
'Hello World!'
end

<r:hello/> will output 'Hello World!'

to render with attribute(s):

define_tag 'hello' do |tag|
name = tag.attr["name"]||'World'
'Hello #{name}!'
end

<r:hello name="nixeon"> will output 'Hello nixeon!'; if name is not present, still show 'Hello World!'

to render using current page info:

define_tag 'hello' do |tag|
page = tag.locals.page
"Hello! #{page.title}"
end

<r:hello> will output "Hello! current_page_title"

to render content inside of tags:

define_tag 'hello' do |tag|
name = tag.expand
"Hello #{name}!"
end

<r:hello>Nixeon</r:hello> will output "Hello Nixeon!"

easy huh? tags can be also defined in behavior by using define_tags method to initialize the batch tags definition.

more about radiantCMS, visit the official official site

No comments: