I am using CkEditor and would like to define a custom template, that uses an AJAX function to load a HTML string. I have been able to define custom templates, but if I use a function for the html property of the template object the function is never exectuted. Is it possible to load a template using AJAX with the default template plugin or do I need to write my own?
config.js
CKEDITOR.editorConfig = function (config) { config.templates_files = ['/pathtomyfile/custom.js']; };
custom.js (defining my custom templates)
CKEDITOR.addTemplates('default', { imagesPath: CKEDITOR.getUrl(CKEDITOR.plugins.getPath('templates') + 'templates/images/'), templates: [ { title: 'Template 1', image: 'template1.gif', description: 'A custom template that does not work', html: function () { alert('This alert is never called'); var html = ''; $.ajax({ url: 'MyGetURL', type: "GET", async: false, success: function (result) { html = result; }, error: function (jqXhr, textStatus, errorThrown) { alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')"); } }); return html; } }, { title: 'Template 2', image: 'template2.gif', description: 'A working custom template', html: '<h1>I Work!</h1>' } ] });