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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值