Monday 25 July 2011

Add WYSIWYG editor to admin custom field

To enable the editor for a certain editable textfield, just use 'wysiwyg' => true, instead of 'wysiwyg' => false. and add 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(). i.e.:

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => false,
'required' => true,
));

After Change

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => true,
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
));

also add this to your controller initAction() before return.

if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
 $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}

That's all done.

6 comments:

  1. Yeah, but where do you add this?

    ReplyDelete
  2. i have add this into custom module field in admin.

    ReplyDelete
  3. Hi, I know the post is a bit old, but I have done what you said and I get a JS error: "tinyMceWysiwygSetup is not defined". Do you have any ideas? Magento 1.5.1.0

    ReplyDelete
    Replies
    1. Its may be you don't correctly placed below code.
      if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
      $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
      }

      Delete
  4. i can`t insert variable plz help me.

    ReplyDelete