在TinyMCE中添加模板项目

问题描述:

我想在tineMCE编辑器中添加“模板项目”。 模板项目充当动态插入数据的占位符。在TinyMCE中添加模板项目

一个例子:

而不是写: “{FirstName}您好,您是{}年岁。” 我想插入一个对象,而不是在保存服务器时替换为“{firstname}”的“{firstname}”。将它加载到编辑器中时还应该将其转回。 应该从下拉列表中选择对象(但是一旦其他事情被修复,应该很容易)。

在这种情况下,你eighter保存时需要更换占位符:

tinymce.activeEditor.onSaveContent.add(function(ed, o) { 
    console.debug(o.element.nodeName); 
    // do your replacement here using a regular expression and the saved value from the dropdown selection 
}); 

或从自己的插件的下拉选择框中选择一个名称时。

要在加载时将其返回,您需要将替换字符串存储在satabase中,并使用正则表达式在启动tinymce时将其替换。

// Andreas from db should be placed in a custom initialisation paramter like this: 
db_firstname_save: '<?php echo $value_from_db; ?>', // $value_from_db = 'Andreas' 

使用正则表达式

tinymce.activeEditor.onInit.add(function(ed) { 
    console.debug('Editor is done: ' + ed.id); 
    // do your replacement here using a regular expression 
    ed.setcontent(ed.getContent.replace(ed.getParam('db_firstname_save'),'{firstname}')); 
}); 

为了选择将名字要保存从下拉菜单,你需要创建自己的插件数据库替换从DB值。如何做到这一点可以在the tinymce documentation wiki找到。