2010-09-16 331 views
1

我想在tineMCE編輯器中添加「模板項目」。 模板項目充當動態插入數據的佔位符。在TinyMCE中添加模板項目

一個例子:

而不是寫: 「{FirstName}您好,您是{}年歲。」 我想插入一個對象,而不是在保存服務器時替換爲「{firstname}」的「{firstname}」。將它加載到編輯器中時還應該將其轉回。 應該從下拉列表中選擇對象(但是一旦其他事情被修復,應該很容易)。

回答

0

在這種情況下,你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找到。

相關問題