Closed (fixed)
Project:
Wysiwyg
Version:
7.x-2.0
Component:
Plugins
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Mar 2011 at 01:30 UTC
Updated:
18 May 2011 at 19:40 UTC
Anyone ever successfully added ckeditor Templates?
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Templates
Here's what I'm trying, but it's not working (in a custom module called 'glue'):
function glue_wysiwyg_plugin($editor, $version) {
if ($editor == 'ckeditor'){
return array(
'Templates' => array(
'url' => 'http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Templates',
'internal' => false,
'path' => 'sites/all/libraries/ckeditor/plugins/templates/dialogs',
'filename' => 'templates.js',
'buttons' => array(
'templates' => t('Templates'),
),
'options' => array(
'templates' => 'mytemplates',
'templates_files' => '[\'/sites/all/libraries/ckeditor_tpls/mytemplates.js\']',
'templates_replaceContent' => false,
),
'load' => true,
),
);
}
}
I set the internal path to false, although this is native plugin to ckeditor - but the plugin path was showing up wrong when I tried to set it to true. It was looking for plugin.js..
Any help would be appreciated!
Comments
Comment #1
wheelercreek commentedI should mention, the plugin button shows up, and I can check the box.. but getting a js error when the editor tries to load.
Comment #2
twodYou might want to try the Wysiwyg template plugin which supports the native template functionality of TinyMCE, CKEditor and FCKeditor.
I would suggest changing the implementation to read
'internal' => TRUE,and removing'path' => '...',and'filename' => '...',.The 'internal' property would indicate that the plugin is located in the editor's own plugins folder (as in being bundled with the editor). The 'path' and 'filename' will be ignored (or rather, auto-generated and overridden) when 'internal' is TRUE, and you also won't have to figure out if the editor was put in sites/all/libraries, sites/default/libraries or sites//libraries.
The uncompressed/dev variant of CKEditor does use a plugin.js file (ckeditor/_source/plugins/templates/plugin.js), but the compressed variant which Wysiwyg loads by default has merged the plugin.js files into ckeditor.js.
I think the auto-generation of 'path'/'filename' might have a bug when the uncompressed variant is used and 'internal' is TRUE, I'll look into that later and create a separate bug report if I can verify it.
It looks like you've confused the plugin and button internal names, the plugin is "templates" while the button is "Templates".
Also change the
'template_files'option to be a real array. Drupal knows how to convert a PHP array to a JavaScript Array, but since you're now sending a string, the plugin gets a String instead of an Array.Here you will have to add some extra code to check the site-specific folders, unless you decide to only allow one set of templates in sites/all/libraries/ckeditor_tpls. (Good call placing those outside CKEditor itself!)
Here's the code with the above modifications applied:
UPDATE: I forgot that the templates plugin is registered and loaded by default, as most of the bundled plugins are.
When Wysiwyg sees
'load' => TRUE, it interprets it as "register the plugin file and add it to the list of plugins". For CKEditor, this means callingCKEDITOR.plugins.addExternal(...)and adding the plugin to the extraPlugins setting. That list of plugins is added by CKEditor to its plugins setting, which 'templates' is already in (it is auto-registered by ckeditor/_source/plugins/templates/plugin.js).So, we do not need to explicitly load the plugin at all. We can just write
'load' => FALSEand the button works as expected anyway.Since CKEditor recommends not to modify the 'plugins' setting, we can be reasonably sure the templates plugin is always loaded by default. The removePlugins setting can be used to put a "veto" against certain plugins being loaded, but if someone does that they obviously did not intend to use templates (and the button simply won't show even if added to the toolbar).
Comment #3
wheelercreek commentedYeah! that totally worked. Thanks a ton! I love giving preset templates to my clients - because it just solves a lot of design issues.. and this was the one thing I couldn't figure out how to do with the WSYWYG module.
Comment #4
twodYou're welcome. =)
I've thought about the possibility of merging the templates module mentioned above into Wysiwyg itself, but for now we need to focus on improving our own API.
Comment #6
miaoulafrite commentedHello,
sorry to re-open the issue
i have the same problem
i run it in Drupal 6.x
Version of CKEditor is 3.5.3
i'm not using the CKEditor module
i also installed Wysiwyg template plugin
thanks to Wysiwyg template plugin i can see the "template icon" while editing some content with CKEditor as described in their documentation
this doc states that there are three default templates:
The dialog window shows a list of pre-defined templates that are available in your system. The standard installation of CKEditor contains three basic templates, however, this list may be expanded as needed.
these templates do not show up in drupal (admin/settings/wysiwyg/templates): why?
to make this happen, is that mandatory to create another module as described above?
what relation these HTML template have with the templates described here:
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Templates
i'm confused, i just want to allow users to create content on two-columns based templates
thanks for your help
Comment #7
twod@miaoulafrite, You do not see the three default templates because the Wysiwyg template module sets CKEditor's template_files setting to point to a different path. See the "Pointing the Editor to a Custom Templates Definition File" section in your last link.
The new path does not point to an actual file but one of wysiwyg_template.module's page callbacks, so it can dynamically generate the list of templates created using that module.
This means the templates defined in the original ckeditor/plugins/templates/templates/default.js are no longer loaded. You'll have to recreate them using wysiwyg_template.module's interface if wysiwyg_template.module doesn't include similar templates by default. Exactly how to do that is better to ask in their issue queue.