Pending Review
Last Updated: 06 Feb 2017 09:34 by ADMIN
anirudh
Created on: 09 Aug 2011 13:34
Category: Templates
Type: Feature Request
23
Place templates in external file
Hi,

We're building a large JS app that uses jQuery templates. When the number of templates got out of hand, I moved it to another HTML page, and did a $.get("templates.html") and appended that to the DOM.

We load each template one by one. We wanted to do parallel loading using something similar to head.js

Maybe you guys can come up with a way of doing it neater. Maybe something like this:

kendo.templates.remote = ['templates1.html', 'templates2.html'];
kendo.ready(function(){ //kick ass! });
5 comments
Russell
Posted on: 18 Dec 2015 15:58
Don't make me write a bunch of custom code (or copy somebody's solution) to load MVVM templates from a remote source.

Using remote templates is a standard practice that is supported in other frameworks (like AngularJS). It should be supported out-of-the-box.

Add a remote template loader, which has the following characteristics:
* Expose a method which accepts an array of template specifications. Each specification has the following properties:
 path: the URL to load the template from
 tag: the ID to use for the script tag
* Loaded templates should be wrapped in a <script> tag with type="text/x-kendo-template"> and appended to the DOM.
* Return a jQuery Promise object, which is resolved when all of the specified templates have been loaded and appended to the DOM.
* Reject the Promise if any of the templates fail to load.


The following is a homebrew solution somebody posted, which uses a DOM event to signal readiness:
https://gist.github.com/amirgalor/8705653

This is a good starting point, but not ideal if you have multiple UI scripts which are each loading their own templates.
ADMIN
Telerik Admin
Posted on: 23 May 2014 11:24
Indeed RequireJS would be the preferred option at this point to load templates asynchronously. 
Imported User
Posted on: 22 May 2014 10:51
I'm using requirejs to load my templates, for me this is ok, but build in way would be better
Imported User
Posted on: 07 Sep 2011 04:38
I keep my jQuery templates in an external javascript file and load them in that way...means there's no appending going on and the file is cached

...so I would say allow templates to live in javascript :)
ADMIN
Todd
Posted on: 10 Aug 2011 21:08
Thanks for the interesting idea! We'll definitely think about ways to make Templating more "scalable" for large applications.

To other developers- If you also like this idea of external template support, please add your votes!