ckeditor中关于模板的自定义

就是怎么用程序自定义模板吧,以前找了好久都没找出来该怎么做,今天有人给了一个文件,貌似可以。没有测试。

基本大概能看懂,没有翻译,自己水平有限。

Templates

WithCKEditor,contentwriterscanselectatemplatefromalistbyclickingthe"Templates"buttoninthetoolbar.AtemplateisapredefinedpieceofHTMLthatisplacedinsidetheeditor.Inthiswaytheuserdoesn'tneedtostartwritingfromscratch.Designerscanpreparewelldesignedtemplates,avoidingusererrorsbeforetheyhappen.

TemplateDefinitionFiles

Theeditorcomeswiththreesampletemplatesthataretherejusttoshowthewayitworks.Theyaredefinedintothe"plugins/templates/templates/default.js"file.

Developersshoulddefinitelychangethedefaulttemplatesastheyarenotespeciallyusefultoendusers.

NotethatatemplatedefinitionfileisaJavaScriptfilethat'sloadedwhenopeningthetemplatesdialogforthefirsttime.Thisfilemaybechangedtoincludecustomtemplates,orevenbetter,youcancreateaseparatedtemplatefileoutsidetheeditorinstallationdirectory,configuringtheeditortouseit.

PointingtheEditortoaCustomTemplatesDefinitionsFile

AssumingyouhavecreatedacustomTemplatesDefinitionsfilenamed"mytemplates.js"(startingfromacopyofdefault.js)andhaveplaceditintotherootofyourwebsite.Now,justaddthefollowingsettingintheeditorconfiguration:

config.templates_files=['/mytemplates.js'];

Notethatthetemplates_filessettingisanarray,whichmeansthatmorethanonetemplatesfilecanbeused.

TheTemplatesDefinitionsFileContents

ThisisasampleTemplateDefinitionfilethatdefinestwosimpletemplates:

//Registeratemplatesdefinitionsetnamed"default".

CKEDITOR.addTemplates('default',

{

//Thenameofsubfolderwhichholdtheshortcutpreviewimagesofthetemplates.

imagesPath:CKEDITOR.getUrl(CKEDITOR.plugins.getPath('templates')+'templates/images/'),

//Thetemplatesdefinitions.

templates:

[

{

title:'MyTemplate1',

image:'template1.gif',

description:'Descriptionofmytemplate1.',

html:

'<h2>Template1</h2>'+

'<p><imgsrc="/logo.png"style="float:left"/>Typethetexthere.</p>'

},

{

title:'MyTemplate2',

html:

'<h3>Template2</h3>'+

'<p>Typethetexthere.</p>'

}

]

});

Aswecanseehere,theaboveispureJavaScriptcode.It'sasimplecalltotheCKEDITOR.addTemplatesfunction,whichregistersthetemplatesunderauniquename("default").Thisnamecanbethenusedbythetemplatessetting.


你可能感兴趣的:(ckeditor)