Javascript Symfony 5&;FOSCKEDITOR:创建一个简单的自定义插件,该插件的图标不会出现在编辑器工具栏中
我在Symfony5网站上安装了有用的捆绑包fosckeditor(CKEDITOR版本4) 一切正常,我的页面上有CKEDITOR字段。现在我想创建一个新的简单插件 我严格遵循这一点,在Javascript Symfony 5&;FOSCKEDITOR:创建一个简单的自定义插件,该插件的图标不会出现在编辑器工具栏中,javascript,ckeditor4.x,symfony5,Javascript,Ckeditor4.x,Symfony5,我在Symfony5网站上安装了有用的捆绑包fosckeditor(CKEDITOR版本4) 一切正常,我的页面上有CKEDITOR字段。现在我想创建一个新的简单插件 我严格遵循这一点,在/public/bundle/fosckeditor/plugins/中创建了一个名为“timestamp”的新插件,其中包含一些文件: 在plugin.js中,我添加了以下代码: CKEDITOR.plugins.add( 'timestamp', { icons: 'timestamp',
/public/bundle/fosckeditor/plugins/
中创建了一个名为“timestamp”的新插件,其中包含一些文件:
在plugin.js
中,我添加了以下代码:
CKEDITOR.plugins.add( 'timestamp', {
icons: 'timestamp',
init: function( editor ) {
alert('hello test ?'); // this alert appears when I load the page containing the CKEDITOR
editor.addCommand('insertTimestamp', {
exec: function (editor) {
var now = new Date();
editor.insertHtml('The current date and time is: <em>' + now.toString() + '</em>');
}
});
editor.ui.addButton('timestamp', {
label: 'Insert Timestamp',
command: 'insertTimestamp',
toolbar: 'insert'
})
}
});
对于这个简单的示例,我从另一个插件复制/粘贴了一个图标,下面是时间戳图标文件:
最后,我重新加载页面(重新加载+清除缓存)。但是Ckeditor工具栏没有改变,自定义插件在任何地方都不会出现
我试图在fos\u ckeditor.yaml
文件中添加按钮,如下所示:
# ...
fos_ck_editor:
# ...
default_config: main_config
configs:
main_config:
# ...
toolbar:
- {
items:
['timestamp']
}
styles:
# ...
但是我的自定义插件的按钮在CKEditor工具栏中一直缺失。
我在浏览器控制台中没有javascript错误,我不知道我在哪里犯了错误。尝试以下配置: app/templates/ckeditor.html.twig
{% extends "base.html.twig" %}
{% block body %}
<div class="ckeditor">
{{ form_start(form) }}
{{ form_row( form.content ) }}
{{ form_end(form) }}
</div>
{% endblock %}
屏幕截图:
插件目录结构:
app/public/bundles/fosckeditor/plugins/
timestamp/
├── plugin.js
└── timestamp.png
相关链接:
fos\u ckeditor.yaml
文件和FormType文件中的一些选项(尤其是在我的例子中的CKEditorType字段。我使用了选项'config'=>['toolbar'=>'full']
来覆盖fos\u ckeditor.yaml
工具栏选项)。你简单而有效的例子帮助我找到了解决方案,我验证了你的答案:)谢谢!
timestamp/
├── plugin.js
└── timestamp.png