【问题标题】:Custom templates in CKEditorCKEditor 中的自定义模板
【发布时间】:2017-08-06 18:31:17
【问题描述】:

我正在尝试在 CKEditor 中加载一些自定义模板,但无法使其正常工作。

这是 config.js 中处理自定义模板的部分:

config.templates = 'default';
config.templates_files = [ '/mytemplates/mytemplates.js' ];
config.templates_replaceContent = false;

我在 CKEditor 文件夹的根目录中创建了一个 /mytemplates 文件夹,并将 mytemplates.js(内容模板插件随附的 default.js 文件的精确副本)放入其中,但似乎编辑器没有加载它们。我收到以下错误:

Uncaught TypeError: Cannot read property 'imagesPath' of undefined/plugins/templates/dialogs/templates.js 文件的imagesPath = definition.imagesPath, 行中。

有什么想法吗?

提前致谢

【问题讨论】:

    标签: javascript templates ckeditor


    【解决方案1】:

    我设法使用CKEDITOR.getUrl() 函数解决了这个问题:

    config.templates_files = [ CKEDITOR.getUrl( 'mytemplates/mytemplates.js' ) ];
    

    我不知道是否可以使用放置在 CKEditor 文件夹之外的自定义模板。如果是这样,请在此处发表评论。

    谢谢

    【讨论】:

    • 您使用的模板文件的路径是相对的,可能对 CKEditor 当前目录无效,CKEDITOR.getUrl() 是一个好方法。要从 CKEditor 目录之外加载文件,您可以只使用完整的 URL(如 http://yourdomain.com/.../mytemplates.js)或正确的相对 URL(如果文件加载正确,您可以在浏览器开发控制台中看到)。
    • 感谢您的洞察!
    猜你喜欢
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 2014-08-02
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多