CKEditor:如何在编辑器中自动应用/加载模板?
我在我的一个网站中使用所见即所得编辑器 CKeditor。为了更加用户友好,我想在每次使用编辑器时自动加载特定的模板。客户必须应用此模板,以便与网站的其余部分(其设计内容显示在两列中)良好集成,因此我想简化他的任务。
现在,我正在使用我在 CKeditor 论坛上找到的以下代码:
CKEDITOR.replace("newsContent", {
customConfig : "/ckeditor/config/news.js",
on:{ instanceReady : function( ev ) {
this.execCommand('templates');
}
},
});
这几乎很好,因为它允许打开模板选择页面,因此用户可以在编辑之前直接选择模板(他只有一个选择)。
但我想应用(唯一)模板,而不要求用户在模板选择页面中选择它。
所以我想知道是否存在像“execCommand”这样的函数来在编辑器中应用模板?我认为这是我在模板选择页面中单击模板时执行的操作,但我在文档中找不到它。
感谢您的帮助。
I'm using the WYSIWYG editor CKeditor in one of my websites. In order to be more user friendly, I would like to load automatically a specific template each time the editor is used. The customer has to apply this template in order to have a good integration with the rest of the website (which is designed with content displayed in two columns), so I would like to easy his task.
Right now, I'm using the following code that I found on CKeditor forum :
CKEDITOR.replace("newsContent", {
customConfig : "/ckeditor/config/news.js",
on:{ instanceReady : function( ev ) {
this.execCommand('templates');
}
},
});
That's almost good because it allows to open the template selection page, and so the user can choose directly the template before editing (he has only one choice).
But I would like to apply the (only) template without asking the user to choose it in the template selection page.
So I'm wondering if there exist a function like "execCommand" to apply the template in the editor ? I think this is the action executed when I click on the template in the template selection page, but I can't find it in the documentation.
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个对我有用。
this one works for me.
我尝试了完全相同的事情,但我必须报告当前版本的 ckeditor ork 的解决方案不起作用。经过几个小时的时间弄清楚如何强制 ckeditor 加载模板插件(ckeditor 在打开模板对话框后完全加载模板插件),我放弃并决定尝试其他解决方案。如果您想直接使用 .setData 方法,解决方案非常简单:
一旦您拥有所需的 html 模板,只需将其传递给 .setData。
I tried the exact same thing and i have to report that with the current version of ckeditor ork's solution does not work. After hours of spending time figuring out how to force ckeditor loading the template plugin (ckeditor loads the template plugin completely after you opened the templates dialog) i gave up and decided to try other solutions. If you get the idea to use the .setData method directly the solutions are quite simple:
As soon as you have your desired html template, simply pass it over to .setData.
Zima 是对的,你必须首先加载模板,否则你最终会得到 getTemplates 返回未定义的
所以像这样的东西可以解决问题:
Zima is right you must first load the templates otherwise you end up with getTemplates returning undefined
So something like this will solve the problem:
仅供参考,在获取模板之前需要加载模板
希望这对某人有帮助
FYI needed to load templates before getting them
hope this helps someone