3

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

Sujeet
  • 43
  • 1
  • 4

3 Answers3

7

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);
Spencer Fraise
  • 138
  • 2
  • 11
4

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

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • 1
    If you are on J!3.3+ this is getting depreciated! You should be using JEditor directly. Something like: `jimport( 'joomla.html.editor' ); $editor = \JEditor::getInstance();` – jakabadambalazs Jul 02 '14 at 08:22
  • 1
    Actually, when using `\JEditor::getInstance()` you should specify which editor you want otherwise you'll get a 'none' editor - which is a simple textarea. For example `\JEditor::getInstance('jce')` would give you the JCE editor. To make sure, however, that you don't hardcode the name of an editor (like JCE) that someone might not have installed I would use something like this: `$editor = \JEditor::getInstance(\JFactory::getUser()->getParam("editor"));` – jakabadambalazs Jul 02 '14 at 08:59
0

Joomla 3.x

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

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

Dennis Heiden
  • 757
  • 8
  • 16