TinyMCE in Block
Permalink 3 users found helpful
Hello
I am trying to get wysiwyg inside a block I made.
I have this:
and above I'm trying to add tinymce functionality by:
But I get the error
And I'm sure I'm just missing something.
Can anybody help?
Thank you
I am trying to get wysiwyg inside a block I made.
I have this:
and above I'm trying to add tinymce functionality by:
<?php $this->inc('../../blocks/content/editor_init.php'); ?>
But I get the error
Fatal error: Call to a member function getCollectionThemeObject() on a non-object in XXX/concrete/blocks/content/editor_init.php on line 3
And I'm sure I'm just missing something.
Can anybody help?
Thank you
I'm trying to find out how to the same thing. It is not made very clear in the documentation and I really don't know where to start.
Okey, I got it:
I looked at the block "content" in the folder "concrete" how it was done there, since I wanted something similiar.
In the add.php/edit.php you add this line: and in the same folders the files "editor_config" and "editor_init" must be created, and the content copied from the content-block files.
Furthermore, the textarea must have the class "ccm-advanced-editor":
It's maybe possible to just include these from the content block, but I want the editor a bit differently, so for me this is the right thing to do.
One last thing. If you don't want the "Add Files"-bar on the top delete the last line in the "editor_init.php":
I looked at the block "content" in the folder "concrete" how it was done there, since I wanted something similiar.
In the add.php/edit.php you add this line:
$bt->inc('editor_init.php');
Furthermore, the textarea must have the class "ccm-advanced-editor":
It's maybe possible to just include these from the content block, but I want the editor a bit differently, so for me this is the right thing to do.
One last thing. If you don't want the "Add Files"-bar on the top delete the last line in the "editor_init.php":
<?php Loader::element('editor_controls'); ?>
Thanks it's working for me so far. I just need to figure out a few things. For instance, when I close the the editor using the x after I try to edit and do not make any changes. It overlays the page with the tinyMCE.
try doing
global $c;
global $c;
Thank you for your information in this post. I'm running into a bit of a problem though.
When I open my block the first time once going into edit mode it works fine and shows the content of the block in the editor. the problem I'm having is if I close the dialog using either [X]Close, Cancel or even hitting update if I go back in to edit the block more it no longer has the content in the editor and you cant select it to make edits.
Any ideas why this would be happening?
When I open my block the first time once going into edit mode it works fine and shows the content of the block in the editor. the problem I'm having is if I close the dialog using either [X]Close, Cancel or even hitting update if I go back in to edit the block more it no longer has the content in the editor and you cant select it to make edits.
Any ideas why this would be happening?
I realize this is a very old post, but to help those who may come across it...
I had this same problem and narrowed it down to a new tinyMCE instance being created each time a block is edited. The instance the content is being added to is the leftover one from the last edit. As far as I can tell this instance doesn't exist in the dom anymore, just in javascript variable memory. I got around this problem with this piece of javascript:
In auto.js it is executed before the new tinyMCE instance is created.
I had this same problem and narrowed it down to a new tinyMCE instance being created each time a block is edited. The instance the content is being added to is the leftover one from the last edit. As far as I can tell this instance doesn't exist in the dom anymore, just in javascript variable memory. I got around this problem with this piece of javascript:
var instance = tinyMCE.get("editorID"); if( typeof instance != 'undefined' ) { instance.remove(); delete instance; }
In auto.js it is executed before the new tinyMCE instance is created.
I'm new to C5 and of course wanted to created a block with a TinyMCE field, but most of the explanations I got seemed a bit more involved than I figured it should be just to get the "global" editor in place. I didn't want to duplicate all that code in all of my blocks. So, I took a peak at the Textarea attribute type to see how it's done there, and here's where I ended up.
Put this in your block add/edit:
<?php
$this->addHeaderItem(Loader::helper('html')->javascript('tiny_mce/tiny_mce.js'));
Loader::element('editor_init');
Loader::element('editor_config', array('editor_mode' => 'ADVANCED'));
?>
The 'editor_mode' parameter in a default C5 install can be ADVANCED, SIMPLE, OFFICE, or CUSTOM.
Then, with the textarea helper:
<?php echo $form->textarea('field_name', $field_name, array('class'=>'advancedEditor ccm-advanced-editor')) ?>
And there you have it! A couple simple lines to get a TinyMCE textarea.
As my elbows get deeper I'm sure I'll need to customize the editor more and more for different blocks and areas, but this will do for now. Hope that helps!
Put this in your block add/edit:
<?php
$this->addHeaderItem(Loader::helper('html')->javascript('tiny_mce/tiny_mce.js'));
Loader::element('editor_init');
Loader::element('editor_config', array('editor_mode' => 'ADVANCED'));
?>
The 'editor_mode' parameter in a default C5 install can be ADVANCED, SIMPLE, OFFICE, or CUSTOM.
Then, with the textarea helper:
<?php echo $form->textarea('field_name', $field_name, array('class'=>'advancedEditor ccm-advanced-editor')) ?>
And there you have it! A couple simple lines to get a TinyMCE textarea.
As my elbows get deeper I'm sure I'll need to customize the editor more and more for different blocks and areas, but this will do for now. Hope that helps!
Thank you Rushing, this was very useful!