Wednesday, 23 August 2017

How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module

1> Including TincyMCE in Head
Add the following function in your Adminhtml Edit Class
(MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit):

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


2> Enabling in Form Field
Add the following content field in your Adminhtml Form class
(MagePsycho_Demomodule_Block_Adminhtml_Demomodule_Edit_Tab_Form):

$fieldset->addField('content', 'editor', array(
    'name'      => 'content',
    'label'     => Mage::helper('demomodule')->__('Content'),
    'title'     => Mage::helper('demomodule')->__('Content'),
    'style'     => 'height:15em',
    'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    'wysiwyg'   => true,
    'required'  => false,
));

No comments:

Post a Comment