Radiant is a cool tool for managing the contents of a website , however many times you will feel that you need to need to customize things in Radiant , but its hard to do because of the radiant structure  which makes the radiant code not visible directly to you , lack of documentation in creating extensions , but we can overcome by a simple way , which is trying to control the Radiant Page without editing the main Radiant gem Code through some Radiant and Rails Facilities.

I was working in a project where I needed to edit the ( pre-created add page ) view for the admin , to add in certain cases some buttons , links , page parts with new actions to be added . The solution is quite simple…

It is assumed that you have a fair knowledge with Radiant extensions to complete through the steps.

Steps :

1 – Appending code to a written action in the radiant controllers

  • In the activate method in the x_extension.rb file in your extension folder , Open the controller you want to add the functions in , use the rails call back functions ( after_filter , before_filter ) to append the code to the required action

Admin::PageController.class_eval do

after_filter :this_is_a_function  , :only => [:new , :edit ,:update]


# do your code


2- After adding the back end code we need to put the display to this code in the Radiant page  , we can use the radiant ( admin.page.edit , admin.tabs )  to append objects to specific regions in the page , this is the attributes the admin.page.edit object has , these attributes defines certain regions in the page , where Radiant uses these regions to divide the page . You are able to edit in any of these regions , under any conditions without affecting the existing Radiant gem

@regions={:form=>[“edit_title”, “edit_extended_metadata”, “edit_page_parts”],     :form_bottom=>[“edit_buttons”], :parts_bottom=>[“edit_layout_and_type”, “edit_timestamp”],  :main=>[“edit_header”, “edit_form”, “edit_popups”]}>
(  admin.page.edit ) attributes

Example :

Add a button to the bottom of the form in case the page is having a certain page  type (  Archive , normal , not found …) , Add a select list for the user to choose an element  in the bottom part of the page

  • Just add the following lines  in your activate method in the x_extension.rb file

admin.page.edit.form_bottom << “add_button”

admin.page.edit.parts_bottom << “select”

In these two lines , we tell the radiant to add  partials in the named regions ( form_bottom  , parts_bottom )  to be render , as the regions are arrays of partials and the radiant renders the partials in the regions.

  • The only remaining thing is to create the partials

A.  create folder called admin and inside it add the page ( As we write the partials in the admin namespace )

B.  Add the html code you want in the partials you want , you can add conditions inside the partials to make it rendered in some specific page claasses

3. You can add specific page parts to a certain class of pages by the same way of adding actions to controller , you can use the after_save call back and add some code to add a page parts to the page as follows :

Admin::Page.class_eval do

after_save :add_parts


if this.class_name == “X”

this.parts << PagePart.new(:name=> “x” , :filter_id => “y” , :page_id=>this.id  )




This will add a part for the class of pages you choose ..

Hope this will be helpful