2011/04/13

Migrating from FCKeditor is a little easier now

There are tons of site out there that are still using FCKeditor despite the fact that it has been replaced by CKEditor and no work is being done to improve it since long ago.

There are several reasons about that, and one of them is the time cost of upgrading things like the configuration and now there's a little plugin that helps avoid at least one of those problems.

In FCKeditor the definition for Templates (HTML snippets) that the user could insert into the content was available in XML files, but as CKEditor was designed so it could be used in a cross-server environment that meant that the format was changed to JSON in order to load .js files from the server instead of trying to do a XHR that it's quite complex or impossible to do on a foreign server.

But the fact is that most of the people doesn't use CKEditor in such environments and also there are lots of people that have their templates specified in XML files and migrating them to JSON isn't obvious as no tool has been published to carry out that goal. Besides that, I personally find much easier to deal with XML files for the templates instead of the JSON version.

Example of a template in JSON:

   {
    title: 'Image and Title',
    image: 'template1.gif',
    description: 'One main image with a title and text that surround the image.',
    html:
     '<h3>' +
      '<img style="margin-right: 10px" height="100" width="100" align="left"/>' +
      'Type the title here'+
     '</h3>' +
     '<p>' +
      'Type the text here' +
     '</p>'
   },

The same template in XML:

 <Template title="Image and Title" image="template1.gif">
  <Description>One main image with a title and text that surround the image.</Description>
  <Html>
   <![CDATA[
    <img style="MARGIN-RIGHT: 10px" height="100" alt="" width="100" align="left"/>
    <h3>Type the title here</h3>
    Type the text here
   ]]>
  </Html>
 </Template>

In the JSON version you have to use single quotes on each line of the "html" and remember to concatenate everything. In the XML version you just paste whatever you want inside the CDATA comment.

Ok, that's fine. You might like one version or another, but if you want to easily use the XML templates in CKEditor, then upgrade to CKEditor 3.5.3 and add the XmlTemplates plugin.

 

12 comments:

Connie said...

This is really a very helpful information as this editor suffers from missing knowledge ;=)

Unfortunately in many cases the editor is used only with minimal configuration

Thank you for the information

. said...

Hi
sorry, cant get it to work, since i really dont know where to put templates_files : ['xml:fcktemplates.xml'], as you described in your docs/install.html in Point "3. Configure entries". I placed config.extraPlugins='xmltemplates'; into /ckeditor/config.js, vut where to place the other one ? could you please post an code example, that would help me i think. thx a lot!

Alfonso said...

there's a "sample" folder that tries to show how to use it.

If you want to modify your config.js then you have to add a like like config.templates_files : ['xml:fcktemplates.xml']

and if it doesn't load correctly, then check in your server logs, firebug, developer tools, fiddler.... what't the path that it's trying to load the xml and adjust it correctly (it might be easier if you use an absolute path like /ckeditor/plugins/xmltemplates/fcktemplates.xml)

. said...

Thx for your reply, Alfonso. I got it to work as i used the following in the /ckeditor/config.js:

CKEDITOR.editorConfig = function( config )
{
[..]
// enable XML for Templates
config.extraPlugins = 'xmltemplates';
config.templates_files = ['xml:/MyPATH-FROM-WEBROOT-TO/fcktemplates.xml'];
[..]
}

So it works fine for me now.
Thx for that necessarily useful plugin!

Anonymous said...

Hello! We have a saying in Russian, "as you call the boat so it will float"and "without the dirty word it does not work:) Maybe this is not related but since FCKeditor lost the most important letter of your extension for Firefox was not correctly inserted from MSWord. Formatting barely tolerated, although older versions worked. I have not used the extension, but last year worked.

Alfonso said...

Sorry, but I don't understand what do you mean.

I don't know if you are talking about a problem with FCKeditor, or CKEditor, with my Firefox extension "WriteArea" or something else

Anonymous said...

sorry, machine translation is far from perfect, especially with regard to idioms. :) Yes we are talking about your extension to Firefox. I did not use long extension, but recently there was a need. I found that I can not use "paste from MSWORD". But I remember that earlier (last year) and used the formatting is retained. Now insert the text only, and only basic formatting (Bold, Italic). But the size, type, and style is not retained. This is the problem. When this was first manifested can not say. Both the Firefox and your extension is updated.

And about the missing letters from the name of FCKeditor "F" and its connection with the problem of course was a joke. :)
In Russia we have an expression that "without swearword nothing works." For it is because of the pronunciation of consonant FCKeditor with obscene word the author has removed the letter "F" from the name (as stated in Wikipedia:)).

Anonymous said...

sorry, machine translation is far from perfect, especially with regard to idioms. :) Yes we are talking about your extension to Firefox. I did not use long extension, but recently there was a need. I found that I can not use "paste from MSWORD". But I remember that earlier (last year) and used the formatting is retained. Now insert the text only, and only basic formatting (Bold, Italic). But the size, type, and style is not retained. This is the problem. When this was first manifested can not say. Both the Firefox and your extension is updated.

And about the missing letters from the name of FCKeditor "F" and its connection with the problem of course was a joke. :)
In Russia we have an expression that "without swearword nothing works." For it is because of the pronunciation of consonant FCKeditor with obscene word the author has removed the letter "F" from the name (as stated in Wikipedia:))

gdmb said...

Does this still work with version 4.0.1?

Alfonso said...

Does this still work with version 4.0.1?

Have you tried it?

Unknown said...

This plugin is not working in IE9+ with Ck-editor 4.5.

Alfonso said...

That's an old problem in CKEditor 4: http://dev.ckeditor.com/ticket/11778