任何人都知道如何让新的1.4 WYSIWYG编辑器(TinyMCE)使用自定义管理页面?
我在admin-> system-> config部分中创建了一些输入字段的模块,我想让新的编辑器显示在textareas那里,但我无法找到他们是定义的。
答案 0 :(得分:6)
要在特定页面上加载TINY MCE,请在模块的Adminhtml Edit块上使用以下功能:
protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
要为某个可编辑文本字段启用编辑器,只需使用'wysiwyg'=>是的,而不是'wysiwyg'=>假。即:
$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
'required' => true,
));
答案 1 :(得分:2)
以下几个简单步骤可帮助您使TinyMCE与Magento CMS页面配合使用。
js/tiny_mce/tiny_mce.js
路径上访问。
app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php
文件。找到
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => false,
'required' => true,
));
并将其更改为
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => true,
'theme' => 'advanced',
'required' => true,
));
如您所见,此处我们更改了现有属性(“wysiwyg”)值并添加了新属性“theme”。
/lib/Varien/Data/Form/Element/Editor.php
文件,找到方法getElementHtml()。在这里我们改变
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script type="text/javascript">
// <![CDATA[
/* tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});*/
//]]>
</script>';
到
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
//< ![CDATA[
Event.observe(window, "load", function() {
tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});
});
//]]>
</script>';
正如您所看到的,只需要进行三次微小的更改(下载,修改,修改)即可使TinyMCE编辑器正常工作。
希望这会有所帮助。欢呼声。
©Branko Ajzele(source)
答案 2 :(得分:1)
在EW_Press_Block_Adminhtml_Press_Edit中 (EW /新闻/座/ Adminhtml /新闻/ Edit.php) 粘贴此功能
protected function _prepareLayout()
{
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled())
{
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
而不是form.php(EW_Press_Block_Adminhtml_Press_Edit_Tab_Form) /(EW/Press/Block/Adminhtml/Press/Edit/Tab/Form.php) /
'config'=&gt;法师:: getSingleton( 'CMS / wysiwyg_config') - &GT; getConfig(),
添加它,使其如下所示:
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('module')->__('Site Description'),
'title' => Mage::helper('module')->__('Site Description'),
'style' => 'width:400px; height:300px;',
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true
));
现在重新加载页面以查看效果。
答案 3 :(得分:1)
以下是我遵循的步骤。
准备编辑表单中使用的编辑器 应用程序/代码/本地/ myNameSpace对象/ Mymodule中/砌块/ Adminhtml / Mymodule中/ Edit.php
protected function _prepareLayout()
{
// added this code
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
}
parent::_prepareLayout();
}
将textarea转换为编辑器
应用程序/代码/本地/ myNameSpace对象/ Mymodule中/砌块/ Adminhtml / Mymodule中/编辑/标签/ form.php的
在'_prepareForm()'函数
中包含内容$config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array(
'add_widgets' => false,
'add_variables' => false,
'add_images' => false,
'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/',
));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('mymodule')->__('Content'),
'title' => Mage::helper('mymodule')->__(’Content'),
'style’ => 'width:700px; height:320px;',
'wysiwyg' => true,
'required' => true,
'config' => $config,
));
答案 4 :(得分:0)
根据上述帖子,我写了一篇题为:
的文章
How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module
希望这有帮助。