Posted by rp8 on Saturday, September 20, 2008

There are two ways to write your own custom tags in Radiant: Radiant Extension and Rails plugin.

I need to have a feature like Apache’s “Server Side Include” so I can include some static or dynamic content not managed by Radiant. Since it involves with rendering content from a file, I choose to implement a Rails plugin to extend the existing module StandardTags.

The new tag is called <r:include> and here’s an example <r:include virtual=“/test.html”
/>.

No such file or directory – /home/www/competo/public/contents/samples/test.html

Here’re the steps to implement the “include” tag.

1. Create a new folder vendor/plugin/include_tag

2. Create a file init.rb with the following line

require 'standard_tags_ext'

3. Create a new folder vendor/plugins/include_tag/lib

4. Create a new file standard_tags_ext.rb, which will extend the existing module with our new tag


require 'standard_tags'
module StandardTags
    desc %{
      renders the content of a file to the page
      *Usage:*
       <pre><code>&lt;r:include virtual="/xyz.html" />
} tag ‘include’ do |tag| options = tag.attr.dup IO.read(File.join(RAILS_ROOT, ‘public’, options[‘virtual’])) end

end

5. Restart the server and it’s ready to go!