How to add joomla editor in custom component view but without using XML form fields?

家住魔仙堡 提交于 2020-01-01 15:32:07

问题


I am developing a custom joomla component. I want to add a joomla editor field in my one of my component view. I know how to add editor using XML form file (models/forms/myview.xml), but I want to do the same in view file (myview/tmpl/default.php) without using the xml file fields. Is it possible ? If it is then how ?

Please help


回答1:


Try this,

     $editor = JFactory::getEditor();
     echo $editor->display('content', $this->content, '550', '400', '60', '20', false);

For more

In Latest Joomla version J3.x [UPDATE]

you can use something like below,

jimport( 'joomla.html.editor' );
$editor = JEditor::getInstance(JFactory::getUser()->getParam("editor"));
echo $editor->display('content', $this->content, '550', '400', '60', '20', false);

for more




回答2:


I know this is an old question but for what it's worth I figured I would show how to get the default editor set in the global settings instead of by user. Often times users don't have a default editor set and the value that will get returned is 'JEditor' which will cause an editor to not load at all. If you wanted to you could combine the two together to first check the user editor and then fall back to the global one if the value is JEditor.

Here's an example:

// IMPORT EDITOR CLASS
jimport( 'joomla.html.editor' );

// GET EDITOR SELECTED IN GLOBAL SETTINGS
$config = JFactory::getConfig();
$global_editor = $config->get( 'editor' );

// GET USER'S DEFAULT EDITOR
$user_editor = JFactory::getUser()->getParam("editor");

if($user_editor && $user_editor !== 'JEditor') {
    $selected_editor = $user_editor;
} else {
    $selected_editor = $global_editor;
}

// INSTANTIATE THE EDITOR
$editor = JEditor::getInstance($selected_editor);

// SET EDITOR PARAMS
$params = array( 'smilies'=> '0' ,
    'style'  => '1' ,
    'layer'  => '0' ,
    'table'  => '0' ,
    'clear_entities'=>'0'
);

// DISPLAY THE EDITOR (name, html, width, height, columns, rows, bottom buttons, id, asset, author, params)
echo $editor->display('email', '', '400', '400', '20', '20', true, null, null, null, $params);



回答3:


Joomla 3.x

$editor = JFactory::getEditor();
$editor = $editor->display('mce', $yourContent, '550', '400', '60', '20', false);

www.joomla-wiki.de/dokumentation/JFactory/getEditor



来源:https://stackoverflow.com/questions/19064709/how-to-add-joomla-editor-in-custom-component-view-but-without-using-xml-form-fie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!