12/06/2013

How to use WYSIWYG editor TinyMCE in custom Admin Magento Module

It's so easy to enable by the below 3 steps
1) Go to Yournamespace_Modulename_Block_Adminhtml_Modulename_Edit
then copy and paste the below code
protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}


2) In the same File inside public function __construct() function add the following condition
$this->_formScripts[] = "
function toggleEditor() {
if (tinyMCE.getInstanceById('show_content') == null) {
tinyMCE.execCommand('mceAddControl', false, 'show_content');
} else {
tinyMCE.execCommand('mceRemoveControl', false, 'show_content');
}
}
";

If you already have the $this->_formScripts[] then insert function toggleEditor() and it's content to it.

3) Now go to Yournamespace_Modulename_Block_Adminhtml_Modulename_Edit_Tab_Form
$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('show')->__('Description'),
'title' => Mage::helper('show')->__('Description'),
'wysiwyg' => true,
'required' => false,
));

No comments:

Post a Comment