# How to convert a Behavior to a Page Type in a Radiant Extens

**URL:** <https://www.ruby-forum.com/t/how-to-convert-a-behavior-to-a-page-type-in-a-radiant-extens/83067>\
**Category:** Radiant CMS\
**Created:** [January 23, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-behavior-to-a-page-type-in-a-radiant-extens/83067 "2007-01-23T14:25:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorenjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b5a626/32.png) [@lorenjohnson](https://www.ruby-forum.com/u/lorenjohnson)\
**Post date:** [January 23, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-behavior-to-a-page-type-in-a-radiant-extens/83067/1 "2007-01-23T14:25:23Z")

</div>

ROUGH STEPS TO CONVERTING A BEHAVIOR TO A PAGE TYPE PACKAGED AS A  
RADIANT EXTENSION

I’ve ported all my own behaviors to Page Types packaged in Extensions  
within the last day so my mind is fresh on the topic, however this is  
by no means a comprehensive or even wholly accurate guide.

Use at your own risk (SEE ALSO NOTE AT BOTTOM).:

1. Rename the folder of your Behavior and DON’T name it end with  
Extension then move the folder from plugins to extensions so:

# move

/vendor/plugins/comments\_behavior

# to

/vendor/extensions/comments

1. Delete the init.rb file and create a new file called  
“your\_extension\_name\_extension.rb” and fill it with this general:

class CommentableExtension \< Radiant::Extension  
version “0.1”  
description “Blah blah blah which will appear as the description  
of this Extension under the Extensions list in the Mental / new  
Radiant.”  
url “[http://www.fn-group.com/](http://www.fn-group.com/)”

# Happens when the enabled checkbox is check and saved in the

admin Extensions list  
def activate  
# These are Page type classes which were converted from  
behaviors as detailed below  
CommentBucket  
Commentable  
end

# The opposite

def deactivate  
end  
end

1. Classes already in the lib directory are auto-loaded and no longer  
need to be explicitly required. In fact the explicit requiring of the  
classes in the lib directory seems to break things, but no need to  
worry they’re already available.

2. Rename your class appropriately, at least taking off “Behavior”  
from the end of name if it’s there, then inherit from Page not  
Behavior::Base, so:

class CommentableBehavior \< Behavior::Base # becomes  
class Commentable \< Page # Isn’t that neat. We’re just adding right  
onto the page.

1. Comment out or delete the register line, this is no longer  
needed in a Page type and will in fact break things if it’s not removed:

register “Commentable” # becomes

# register “Commentable”

1. Remove the “define\_tags do … end” enclosure. It’s no longer  
needed. Nifty Page types will know what to do with all those "tag “”  
do |tag|"s

2. If you have disabled the page caching in your behavior change:

def cache\_page?  
false  
end

#to

def cache?  
false  
end

1. Search and replace “@page” with “self” …

2. Encapsulate existing comments in “desc %{ what your tag does  
here … }” headers on the line above a tag definition to get a  
description to show-up in the new “Available Tags” link in the Admin  
interface.

3. Restart the web server for your Radiant app, look for errors in  
log/mongrel.log (or later in log/production.log) – repeat.

NOTE  
If you were creating an Extension from scratch you get this framework  
by using “script/generate extension YourExtensionName” …)

This guide in no way demonstrates the power or architecture of the  
new Radiant Extensions which go beyond the scope of behavior and can  
include, among other things an admin interface, custom models, views  
and routes

Loren J.  
[www.fn-group.com](http://www.fn-group.com)

---

<div class="post-metadata">

**Author:** ![lorenjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b5a626/32.png) [@lorenjohnson](https://www.ruby-forum.com/u/lorenjohnson)\
**Post date:** [January 24, 2007, 6:49am UTC](https://www.ruby-forum.com/t/how-to-convert-a-behavior-to-a-page-type-in-a-radiant-extens/83067/2 "2007-01-24T06:49:32Z")

</div>

Loren,  
Thanks for posting this.  
BJ Clark
