How to add custom template to CKEditor?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ethanlazarus
User
Posts: 63

How to add custom template to CKEditor?

Post by ethanlazarus »

Hello - I have added custom templated to CKEditor; however, whenever I regenerate files and upload all files, the templates get erased. Obviously, I can skip uploading the CKEditor files, but I have often inadvertently overwritten my templates.

The template is just the built in plugin from ckeditor, not the template from phpmaker. in the project folder, ckeditor, plugins, templates, templates folder. Each time I regenerate files, the ckeditor plugin gets over-written.

Is there a way for me to make a custom instance of CKEditor that doesn't get over-written on file generation? Would love any thoughts on how to keep my custom CKeditor settings intact.

Thanks!


arbei
User
Posts: 9384

Post by arbei »

You need to explain how you currently added them to your site first. (What files or code? Where you add them to? etc.) In general, you may make your own extension.


ethanlazarus
User
Posts: 63

Post by ethanlazarus »

I actually made a table patient_templates where I could enter my template in a ckeditor field, and then it would add this as a template to the ckeditor extension. This is the code segment:

function update_templates (){                            
     $cc = 0;                       
     $template_file = "CKEDITOR.addTemplates('default',{imagesPath:CKEDITOR.getUrl(CKEDITOR.plugins.getPath('templates')+'templates/images/'),templates:[";
     $query9 = "SELECT * FROM `patient_templates`  ORDER BY display_order ASC";  

     $rows = ExecuteRows($query9);
	 if (count($rows) > 0)
	 foreach($rows as $row)

	{  
       $tname = $row['template_name'];
       $ttext = $row['template_text'];
       $tdesc = $row['template_description'];
       $timage = $row['template_image'];    
       if ($cc == 0)  {
         $cc++; 
         $template_insert = "";
         }
       else $template_insert = ",";
       $template_insert .= "{title:'".
       str_replace("'", "", $tname)."',image:'".
       str_replace("'", "", $timage)."',description:'".
       str_replace("'", "", $tdesc)."',html:'".
       str_replace("'", "", $ttext)."'}";  
       $template_file .= $template_insert;
     }  // while
     $template_file .= "]});";   
     $template_file = str_replace(chr(10), "", $template_file); //remove carriage returns
     $template_file = str_replace(chr(13), "", $template_file); //remove carriage returns  
     
  
     $myFile = "ckeditor/plugins/templates/templates/default.js";
     $fh = fopen($myFile, 'w') or die("can't open file");
     fwrite($fh, $template_file);
     fclose($fh); 
}

arbei
User
Posts: 9384

Post by arbei »

arbei wrote:

Where you add them to?

Where did you add your update_templates() function to? Where did you use it?


ethanlazarus
User
Posts: 63

Post by ethanlazarus »

This code gets called on table patient_templates - the table has id, template_name, template_description, template_image, template_text fields . The template_text is used to build the template.

This is in row_inserted / row_updated


arbei
User
Posts: 9384

Post by arbei »

ethanlazarus wrote:

whenever I regenerate files and upload all files, the templates get erased.

If template is stored in database table and code stored in Row_Inserted/Updated server events, then what were erased? Your CKEditor plugins? If so, again, how did you add them? You better describe your problem in detail.


Post Reply