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.

Comments

  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?

    ReplyDelete
  2. I fixed it, it was the issue with the field name being called 'content' Sorry to waste your time :)

    ReplyDelete
  3. No problem you have fixed your self ;) Thanks for commenting:)

    ReplyDelete
  4. show/hide editor button is display, but editor not display.

    ReplyDelete
  5. Dhara try it once again after clearing cache. Please make sure that you have followed those 2 steps correctly! It's worked perfectly for me. The only problem in this code is i couldn't not able to insert image using image widget. This post having step-by-step screenshot http://www.magentocommerce.com/boards/error.php/viewthread/77009/#t218074 feel free to follow that :)

    ReplyDelete
  6. Same issue with me. I am only geting show/hide editor button, i cleared the cache, and followed the steps but no luck, early help is appriciated

    ReplyDelete
  7. Hi Pankaj, please follow the above sangam's replay link. It's helped me to get the widget with full functionality as like in CMS module.

    ReplyDelete

Post a Comment

Popular posts from this blog

Send email from xampp localhost

Modify item price in cart after placing order using sales_quote_add_item