Magento enable wysiwyg editor in custom module

Wysiwyg editor is very popular in Magento back-end which allows you to enter / edit content. In this post, I will show you how to enable it for a textarea in your custom module. For example, you need to enable it for description field when editing FAQ in backend.
Step 1: Go to app/code/local/Magebuzz/Faq/controllers/Adminhtml/FaqController.php under your editAction() function add this code after loadLayout() function.

$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);

Step 2: Open app/code/local/Magebuzz/Faq/Block/Adminhtml/Faq/Edit/Tab/Form.php, you should enter this code:

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

One thought on “Magento enable wysiwyg editor in custom module”

1 Response to Magento enable wysiwyg editor in custom module

  • Carlos
    Carlos on May 31, 2016 at 10:42 am said:

    How can i work whit multiple editors?
    $fieldset->addField('description', 'editor', array(
    'name' => 'description',
    'label' => Mage::helper('faq')->__('Answer'),
    'title' => Mage::helper('faq')->__('Answer'),
    'style' => 'height:12em;width:500px;',
    'wysiwyg' => true,
    'required' => true,
    'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    ));
    $fieldset->addField('description1', 'editor', array(
    'name' => 'description1',
    'label' => Mage::helper('faq')->__('Answer1'),
    'title' => Mage::helper('faq')->__('Answer1'),
    'style' => 'height:12em;width:500px;',
    'wysiwyg' => true,
    'required' => true,
    'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    ));

Comments