Can you place a jsRender template within a .js file? The reason is, I want to contain my entire plugin, which I want to have use a template instead of writing all the code to dynamically create the nodes, in a single javascript file. Is this possible? If so how? If not, what are my options?
Share
If you create a template in a script block, you can get the compiled function, convert to string, and put it into your script file:
Run the code:
var compiledFunctionString = $( "#myTemplate" ).template().toString();Copy the string value of the resulting compiledFunctionString (which will be of the form
"function anonymous($data, $view) { ...content... }") and put it into your script file as:function myTemplate($data, $view) { ...content... }.Now you can use it as in: