Friday, 27 April 2012

wysiwyg editor in Magento Custom Module

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
public function _prepareLayout()
{
if (Mage::getSingleton(‘cms/wysiwyg_config’)->isEnabled() && ($block = $this->getLayout()->getBlock(‘head’))) {
$block->setCanLoadTinyMce(true);
}
return parent::_prepareLayout();
}
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);
$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/’));
then define this as $fieldset
$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,
));
This post is original on webkul