CKEDITOR.template
Lightweight template used to build the output string from variables.
// HTML template for presenting a label UI.
var tpl = new CKEDITOR.template( '<div class="{cls}">{label}</div>' );
alert( tpl.output( { cls: 'cke-label', label: 'foo'} ) ); // '<div class="cke-label">foo</div>'
// Since 4.12.0 it is possible to pass a callback function that returns a template.
var tpl2 = new CKEDITOR.template( function( data ) {
return data.image ? '<img src="{image}" alt="{label}"/>' : '{label}';
} );
alert( tpl2.output( { image: null, label: 'foo'} ) ); // 'foo'
alert( tpl2.output( { image: '/some-image.jpg', label: 'foo'} ) ); // <img src="/some-image.jpg" alt="foo"/>
Filtering
Properties
-
The current template source.
Note that support for the
Functiontype was added in version 4.12.0 .
Methods
-
constructor( source ) → templateCKEDITOR.template#constructorCreates a template class instance.
Parameters
source : String | FunctionA string with the template source or a callback that will return such string. The handling of the
Functiontype was added in version 4.12.0 .
Returns
template
-
output( data, [ buffer ] ) → String | NumberCKEDITOR.template#outputProcesses the template, filling its variables with the provided data.
Parameters
data : ObjectAn object containing properties whose values will be used to fill the template variables. The property names must match the template variables names. Variables without matching properties will be kept untouched.
[ buffer ] : ArrayAn array that the output data will be pushed into. The number of entries appended to the array is unknown.
Returns
String | NumberIf
bufferhas not been provided, the processed template output data; otherwise the new length ofbuffer.