From bit to a heart beat

insane innovations from a sane insanity

Fri Oct 30

Using widgets in web2py (integrating CKEditor)

Although web2py comes with an integrated editor, I really like ckeditor and using it for a text field is trivial using widgets!

First, install ckeditor (put the ckeditor inside a js/ckeditor file in your static folder and include it) :

<script type=”text/javascript” src=”{{=URL(request.application,’static’,’js/ckeditor/ckeditor.js’)}}”></script>

After that, we define a ‘body’ text field (or whatever name you like):

db.define_table(‘page’,
# more Fields …
Field(‘body’, ‘text’))

Then, inside your db.py (or to another file in your models directory) put the widget:

def advanced_editor(field, value):
return TEXTAREA(_id = str(field).replace(‘.’,’_’), _name=field.name, _class=’text ckeditor’, value=value, _cols=80, _rows=10)

and use the widget

db.page.body.widget = advanced_editor

From now, SQLFORM will use ckeditor to show/edit/save data!

CkEditor in web2py

Comments (View)
blog comments powered by Disqus