ckeditor中关于模板的自定义

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

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

Templates

With CKEditor, content writers can select a template from a list by clicking the "Templates" button in the toolbar. A template is a predefined piece of HTML that is placed inside the editor. In this way the user doesn't need to start writing from scratch. Designers can prepare well designed templates, avoiding user errors before they happen. 

Template Definition Files 

The editor comes with three sample templates that are there just to show the way it works. They are defined into the "plugins/templates/templates/default.js" file. 

Developers should definitely change the default templates as they are not especially useful to end users. 

Note that a template definition file is a JavaScript file that's loaded when opening the templates dialog for the first time. This file may be changed to include custom templates, or even better, you can create a separated template file outside the editor installation directory, configuring the editor to use it. 

Pointing the Editor to a Custom Templates Definitions File 

Assuming you have created a custom Templates Definitions file named "mytemplates.js" (starting from a copy of default.js) and have placed it into the root of your web site. Now, just add the following setting in the editor configuration: 

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

Note that the templates_files setting is an array, which means that more than one templates file can be used. 

The Templates Definitions File Contents 

This is a sample Template Definition file that defines two simple templates: 

// Register a templates definition set named "default".

CKEDITOR.addTemplates( 'default',

{

// The name of sub folder which hold the shortcut preview images of the templates.

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

// The templates definitions.

templates :

[

{

title: 'My Template 1',

image: 'template1.gif',

description: 'Description of my template 1.',

html:

'<h2>Template 1</h2>' +

'<p><img src="/logo.png" style="float:left" />Type the text here.</p>'

},

{

title: 'My Template 2',

html:

'<h3>Template 2</h3>' +

'<p>Type the text here.</p>'

}

]

});

As we can see here, the above is pure JavaScript code. It's a simple call to the CKEDITOR.addTemplates function, which registers the templates under a unique name ("default"). This name can be then used by the templates setting. 


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值