Did anybody yet get the "Template" plugin of Tinymce up and running in Drupal? I'm finding this a very nice feature and one thing that put fckeditor above Tinymce for a while.

In the moxiecode documentation it says to initialize it by putting this code in the template:

tinyMCE.init({ theme : "advanced", mode : "textareas", plugins : "template", theme_advanced_buttons3_add : "template" template_cdate_classes : "cdate creationdate", template_mdate_classes : "mdate modifieddate", template_selected_content_classes : "selcontent", template_cdate_format : "%m/%d/%Y : %H:%M:%S", template_mdate_format : "%m/%d/%Y : %H:%M:%S", template_replace_values : { username : "Jack Black", staffid : "991234" }, template_templates : [ { title : "Editor Details", src : "editor_details.htm", description : "Adds Editor Name and Staff ID" }, { title : "Timestamp", src : "time.htm", description : "Adds an editing timestamp." } ] });

Well, I did this but still the template button does not show up.

As I understand, this kind of manual initialisation should not be necessary in drupal, because plugins can be activated on the config page for "buttons and plugins" in the admin panel.

But alas, the template plugin is not shown there, so what can I do?

Comments

joelpittet’s picture

Tinymce module doesn't support template_templates as of 1.90.4.23

But you can hack it:

Look for this line around line 109
if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{' ) {

Change it to this:
if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{' && $v[0] != '[') {

Then in your templates.php file add something like this:


// Overwriting the arrangement of buttons in TinyMCE's toolbar
function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
    $init = theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running);

    if (isset($init)) {
        array_push($init['plugins'], "template");
        // This used to be quoted by the module and now it will act as the intended js literal array
        $init['template_templates'] = "[";
        $root = dirname(dirname(dirname(__FILE__)));
        //echo "root: ".$root;
        $d = dir($root . "/files/snippets");
        $snippets = array();
        while (false !== ($entry = $d->read())) {
            if( strripos($entry, '.htm' ) !== FALSE ) {
                $snippetName = str_replace(".htm", "", $entry);
                $snippetName = preg_replace('/(_|\-)/', ' ', $snippetName);
                $snippetName = ucwords(trim($snippetName));
                $snippets[] = '{title : "' . $snippetName . '",src : "/files/snippets/' . $entry . '",description : "Adds ' . $snippetName . '"}'."\n";
             }
        }
        $d->close();
        $init['template_templates'] .= join(',', $snippets);
        $init['template_templates'] .= "]";
        /*
        [{
            title : "Editor Details",
            src : "/files/snippets/editor_details.htm",
            description : "Adds Editor Details"
        },
        {
            title : "Action Sheet Body",
            src : "/files/snippets/Action_Sheet_Body.htm",
            description : "Adds Action Sheet Body"
        }]
        */
    
    }
    return $init;
}


Hope that helps

mhuebl’s picture

It also works if you add this to your plugin_req.php

	if (is_dir(drupal_get_path('module', 'tinymce') . '/tinymce/jscripts/tiny_mce/plugins/template/')) {
		$plugins['template'] = array();
		$plugins['template']['theme_advanced_buttons3'] = array('template');
	}

Change the tinymce.module like joelpittet mentioned above

if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{' && $v[0] != '[') {

And then add this to your theme_tinymce_theme() function in tinymce.module or in your template.php

if (isset($init)) {
 switch ($theme_name) {
  case 'advanced': 
    $init['template_templates'] = array('[{title : "Editor Details", src : "'.base_path().drupal_get_path('module','tinymce').'/tinymce/jscripts/tiny_mce/yourtemplatefile.htm",description : "Adds Editor Details"}]');
   break;
 }
}

More Infos about Templates can you find here:
http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template#Each_templa...

mikespainhower’s picture