Ckeditor从数据库加载模板

Ckeditor load templates from database

本文关键字:加载 数据库 Ckeditor      更新时间:2023-09-26

我想让用户能够设置自己的模板在编辑器中使用,问题是我不知道如何设置。

我为模板创建了表,并使用php函数从数据库中检索数据,但我无法在门户中显示它。

我在另一个问题中看到了这一点:

CKEDITOR.editorConfig = function (config) {
        config.templates_files = ['js/editor/plugins/templates/templates/custom.js'];
    };
CKEDITOR.replace( 'editor1', {
    templates: 'my',
    on: {
        instanceReady: function( argument ) {
            var httpRequest = new XMLHttpRequest();
            httpRequest.onreadystatechange = function() {
                CKEDITOR.addTemplates( 'my', {
                    templates: [
                        {
                            title: 'My Templates',
                            html: this.responseText
                        }
                    ]
                });
            };
            httpRequest.open( 'GET', 'in/ver.php?cons=8' );
            httpRequest.send();
        }
    }
});

但它似乎无论如何都不起作用,而且我找不到任何关于它的文档

最后,我通过覆盖模板按钮的操作来解决问题:

CKEDITOR.on('instanceReady', function (ev) {

        var editor = ev.editor;
var cargaPlantilla = new CKEDITOR.command(editor, {
            exec: function(editor){
                $( '#modal' ).fadeIn();
                $.post("in/ver.php?cons=8",{algo: "algo"},function(exito){
                    $("#modal").html(exito);
                });
                $( '#modal-background' ).fadeTo( 500, .5 );
            }
        });
ev.editor.commands.templates.exec = cargaPlantilla.exec;
    });
CKEDITOR.replace('editor1');