I use icanhaz.js and a mustache to download templates, and I download mustache templates on demand using the following method:
loadTemplate: function(name, callback) { if (!ich.templates[name+"_template"]) { jQuery.get("/js/templates/"+name+".mustache", function(data) { window.ich.addTemplate(name+"_template", data); callback(); }); } else { callback(); } }
By checking the data variable that is returned in the debugger, however, it is sometimes returned as a Document object, not a raw string that I can use. I sometimes say because the template loads as desired if the html in the template file does not have a nested DOM element at the top of the file. This is a very strange behavior that I would really like to explain.
So, for example, the template file:
<div> <div>My name is {{name}}</div> </div>
will be returned as a Document object upon loading.
While this template file:
<div></div> <div> <div>My name is {{name}}</div> </div>
returned as raw string.
I am not sure why having this top div without any children should matter in that the template is identified as a Document in relation to the line. Any ideas?
source share