I am trying to write a function to load templates in external files and use them with jsrender
. However, I am getting this error:
TypeError: elem.getAttribute is not a function
[Break On This Error]
value = $templates[elem.getAttribute(tmplAttr)];
I have some console.logs
showing that the template was retrieved with ajax.
The basic code that causes the error is as follows:
var path = 'templates/myTemplate.tmpl.html';
var data = searchResultTeasers;
var target = $('#results');
$.ajax({
url : path,
aysnc : false,
success : function(template) {
console.log("Path", path);
console.log("Template", template);
console.log("Data", data);
//=============================================
// Save Template with url as name for future
//=============================================
$.templates(path, template);
//=============================================
// Get Template String
//=============================================
var templateString = $.templates(path);
//=============================================
// Render Template
//=============================================
renderedTemplate = templateString.render(data);
target.html(renderedTemplate);
}
});
The error is in jsrender.js (line 829) and I think it's concerning the $.templates(path); but I don't understand what could be wrong.
Here is a link to a zip of the project: http://sdrv.ms/QsZpQT
I based my function on this article: http://msdn.microsoft.com/en-us/magazine/hh975379.aspx
I'm not sure if this is jsRender related at all but it still is blocking me from continuing and I would appreciate any help.
async: false
on ajax calls (and you also misspelled async). – Idola