Websnippetz

Get cool snippets on php, css, jQuery, Magento and wordpress

Add tinyMCE editor in magento custom module

If we have created a custom module using Magento Module creator means, it will not contain ‘wysiwyg(tinyMCE)’ editor feature.
We can add the ‘wysiwyg’ editor in custom module within 2 steps.
Step 1:
Add the following code in /controllers/Adminhtml/BlogController.php under the line $this->getLayout()->getBlock('head')->setCanLoadExtJs(true).

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

Step 2:Add the following code in /Block/Adminhtml/Blog/Edit/Tab/Form.php file, within your field declaration.

'config'      => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),

Now, it will look like this


$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('blog')->__('Content'),
'title' => Mage::helper('blog')->__('Content'),
'style' => 'width:900px; height:500px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
'required' => true,
));

That’s it! We have added tinyMCE editor in our magento custom module:)

Note: Field name should not be ‘content’ if you keep your field as ‘content'(which is already available), editor will be shown all over the admin content block. So give some other name for content filed.

karthi s

7 thoughts on “Add tinyMCE editor in magento custom module

  1. Hi, thanks for the tutorial, one problem I've encountered is that after following this guide the whole form is placed within the wysiwyg editor rather than just applying the editor to the specified field.

    Any advice?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: