wysiwyg editor in Magento Custom Module

wysiwyg editor in Magento Custom Module : This is very and well known problem for every magento developer . so here is a simple solutions to add the wysiwyg editor in magento module  development .

Step 1 – Go to app/code/local/Webkul/Faq/Block here webkul is namespace and faq is module name , under your _prepareLayout() function add this code


[stextbox id=”info” shadow=”true”]public function _prepareLayout()
{
if (Mage::getSingleton(‘cms/wysiwyg_config’)->isEnabled() && ($block = $this->getLayout()->getBlock(‘head’))) {
$block->setCanLoadTinyMce(true);
}
return parent::_prepareLayout();
}[/stextbox]

Then go to app/code/local/Webkul/Faq/Block/Adminhtml/Faq/Edit/Tab

and add following code in your _prepareForm() function  below your setform() . $this->setForm($form);

[stextbox id=”info” shadow=”true”]$wysiwygConfig = Mage::getSingleton(‘cms/wysiwyg_config’)->getConfig(array(‘add_variables’ => false, ‘add_widgets’ => false,’files_browser_window_url’=>$this->getBaseUrl().’admin/cms_wysiwyg_images/index/’));[/stextbox]

then define this as $fieldset

[stextbox id=”info” shadow=”true”]$fieldset->addField(‘body’, ‘editor’, array(
          ‘name’      => ‘body’,
          ‘label’     => Mage::helper(‘faq’)->__(‘Content’),
          ‘title’     => Mage::helper(‘faq’)->__(‘Content’),
          ‘style’     => ‘width:700px; height:500px;’,
          ‘state’     => ‘html’,
          ‘config’      => $wysiwygConfig,
          ‘wysiwyg’   => true,
          ‘required’  => true,
      ));[/stextbox]

now go to app/design/adminhtml/default/default/layout and add this xml code
[stextbox id=”info” shadow=”true”]<faq_adminhtml_faq_edit>
       <update handle=”editor”/>
    </faq_adminhtml_faq_edit>[/stextbox]

where first faq is module name and second faq is model name . Bingo you have working wysiwyg editor in magento 🙂

Reindex data from magento after adding this

. . .

Comment (1)

Add Your Comment

  • deepika
    not working 🙁
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close