I have a couple of jsRender templates that are used on all pages. Instead of using the script tag method, I would prefer to precompile them and put resulting functions in an external js file.
I saw a previous question that asked this but the method described doesn't seem to work anymore or I am doing something wrong.
I called $.templates("#myTemplate") from the console which msanjay suggested and copied/renamed the anonymous function and get something like this (which looks a bit odd to my untrained eye):
function myTemplate(data, view, j, b, u) {
var j = j || jQuery.views, h = j.converters.html, ret; try {
return "<div...";
} catch (e) { return j._err(e); }
}
If I then try and use this template by calling var html = $.render( data, myTemplate ); I get an error:
Uncaught TypeError: Property 'render' of object function (a,b){return new p.fn.init(a,b,c)} is not a function
Not sure if the jsRender has changed and this is no longer possible or if I am doing something wrong, but any guidance would be highly appreciated.
$.renderseems not to be a function, in other words. Always best to provide a demonstration, such as with jsFiddle. - Jared Farrish