Opened 5 years ago

Last modified 5 years ago

#11828 confirmed New Feature

Content Templates Improvement

Reported by: Chuck Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0
Keywords: Cc:

Description

Templates are very useful, but if a site has a large number of templates or very complex templates, the load on the editor can get rather large. I would suggest an option to provide a URL as an alternative to the html variable. I have set this up in my own tests and this works well. In my example, it expects the return data to all be JSON arrays with the actual HTML in the "result" param, but it could also take raw HTML instead if needed.

In the template plugin, around line 50 there is currently this line...

item.on('click', function(){

I moved the insertTemplate call into an if statement, so now it reads this way...

if(template.url){

var hmtlData = ; var ajaxOptions = {

async : false, url : template.url, success : function(data, status, xhr){

htmlData = data.result;

}

}; jQuery.ajax(ajaxOptions); insertTemplate( htmlData );

}else{

insertTemplate( template.html );

}

Basically, if the chosen template has a URL, it will load via ajax (async off) and populates, rather than using the HTML attached. This also solves other issues, like needing to encode templates inside JS files or not being able to access HTML based templates from the server.

Change History (1)

comment:1 Changed 5 years ago by Jakub Ś

Keywords: Plugin Templates removed
Status: newconfirmed
Version: 4.3.44.0

@mediamacros thank you for the idea and proposed solution.

You could add it as a pull request to https://github.com/ckeditor/ckeditor-dev. That way such solution can be checked much faster.

IMHO this is nice starting point - templates could accept HTML or URL to make e.g ajax call and get JSON or URL to JS file with templates and add it as script tag to page.

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy