Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

CKEditor plugin

Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Smarty n00b

Joined: 10 May 2010
Posts: 1

PostPosted: Mon May 10, 2010 12:13 pm    Post subject: CKEditor plugin Reply with quote

I was some rewriting code of old FCKEditor plugin so the new CKEditor will working under Smarty tamplate.
It is based on prewious plugin for FCKEditor.
I have write it just few minuts ago, so please test it and... improve it as well.

 * Smarty plugin
 * @package Smarty
 * @subpackage plugins

* Smarty function plugin
* Requires PHP >= 4.3.0
* -------------------------------------------------------------
* Type:     function
* Name:     ckeditor
* Version:  0.9
* Author:   cezaryece based on plugin for fckeditor by gazoot (gazoot care of gmail dot com)
* Purpose:  Creates a CKeditor, a very powerful textarea replacement.
* -------------------------------------------------------------
* @param InstanceName Editor instance name (form field name) [ plugin has feature of multiply instances of CKEditor, but not tested yet]
* @param BasePath optional Path to the FCKeditor directory. Need only be set once on page. Default: /FCKeditor/
* @param Value optional data that control will start with, default is taken from the javascript file
* params from CKEDITOR.config fields list
* @param width optional width (css units)
* @param height optional height (css units)
* @param toolbar optional what toolbar to use from configuration
function smarty_function_ckeditor($params, &$smarty) {
   if(!isset($params['InstanceName']) || empty($params['InstanceName'])) {
      $smarty->trigger_error('ckeditor: required parameter "InstanceName" missing');

   $CKEditor = 'CK_'.$params['InstanceName'];
   $base_arguments = array();
   $config_arguments = array();

   // Test if editor has been loaded before
   if(!count($base_arguments)) $init = TRUE;
   else $init = FALSE;

   // BasePath must be specified once.
   if(isset($params['BasePath'])) {
      $base_arguments['BasePath'] = $params['BasePath'];
   else if(empty($base_arguments['BasePath'])) {
      $base_arguments['BasePath'] = 'js/ckeditor/';

   $base_arguments['InstanceName'] = $params['InstanceName'];

   if(isset($params['Value'])) $base_arguments['Value'] = $params['Value'];

   // Use all other parameters for the config array (replace if needed)
   $config_arguments = array_diff_assoc($params, $base_arguments);

   $out = '';

   if($init) {
      $out .= '<script type="text/javascript" src="' . $base_arguments['BasePath'] . 'ckeditor.js"></script>';

   $out .= "\n<script type=\"text/javascript\">\n//<![CDATA[\n";
   $out .= "var ".$CKEditor." = CKEDITOR.replace('".$base_arguments['InstanceName']."');\n";
   $out .= $CKEditor.".basePath = '".$base_arguments['BasePath']."';\n";
//    $out .= $CKEditor.".setData = '".htmlspecialchars($base_arguments['Value'])."';\n";

   foreach($config_arguments as $key => $value) {
      if(!is_bool($value)) {
      // Fix newlines, javascript cannot handle multiple line strings very well.
         $value = '"' . preg_replace("/[\r\n]+/", '" + $0"', addslashes($value)) . '"';
      $out .= "$CKEditor.config.$key = $value; ";

   $out .= "//]]>\n</script>\n";
   $out = "<textarea name='".$base_arguments['InstanceName']."'>".$base_arguments['Value']."</textarea>\n".$out;
   return $out;

Save this code as function.ckeditor.php in your Smarty plugins directory.
Invoking from template:
{ckeditor InstanceName='ckedit' Value=$text width=600 height=400 toolbar=Basic}

Back to top
View user's profile Send private message
Smarty n00b

Joined: 09 Nov 2011
Posts: 1

PostPosted: Wed Nov 09, 2011 5:23 am    Post subject: ckeditor plugin not working Reply with quote

Plugin not working. Instead of editor it just display textarea with specified width and height. I try to debug it, I found ckeditor.js file not loaded. So what should I do ?

Last edited by avinash on Wed Nov 09, 2011 5:25 am; edited 1 time in total
Back to top
View user's profile Send private message
Smarty n00b

Joined: 20 Oct 2011
Posts: 2

PostPosted: Sat Dec 03, 2011 8:29 am    Post subject: Reply with quote

I've written a custom plugin for CKEditor--successful on all fronts, save one currently: I can't, for the life of me, figure out how to customize the image on the button in the toolbar of the editor. As I'm a new user, you'll have to click through to see attached image; the highlighted square in the top left should have a pretty picture (like most of the other toolbar items).
Thanks much for thoughts/advice/help.
Back to top
View user's profile Send private message
Smarty Rookie

Joined: 18 Dec 2011
Posts: 5

PostPosted: Mon Dec 17, 2012 11:52 am    Post subject: Reply with quote

Thanks God someone watches ... Very Happy

Somebody tested this plugin? Is this written in a Smarty Plugin way?
When I can find a proper and working CKEditor plugin?

I've found some information about integration with PHP but it's very old.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP