BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

template is not parsed correctly in ff4 #109

Closed chrismarx closed 13 years ago

chrismarx commented 13 years ago

here is the jsfiddle test :

http://jsfiddle.net/nick_craver/Tgwcd/

when using ${} in a html attribute on ff, it doesn't get recognized and parsed as template code-

chrismarx commented 13 years ago

i realize this could be avoided by using a script tag to contain the template, but im using ajax to bring in a html file multiple templates, and jquery parsed out the scripts when getting the content, and made it so i couldn't access templates inside scripts tags-

BorisMoore commented 13 years ago

Wrapping in a div is not supported. Browsers serialize in ways that will break templates. Bringing the templates as an HTML file is probably not a good idea. If you can't get the scripttag content from the file, you will have to fetch the template(s) as string, e.g. in a text file or js file.

This is the same problem (trying to use HTML content as a template) as in the following: https://github.com/jquery/jquery-tmpl/issues/5 https://github.com/jquery/jquery-tmpl/pull/31 Note that templates are not necessarily even well-formed HTML, so it is not possible in general (and is not supported) to get them from HTML content as such...

chrismarx commented 13 years ago

ok, thanks for the info, i worked out what was going on with the jquery ajax call for the remote html file with scripts, this works now:

BasePanel.getTemplate = function(){ var $templates; //use filter to just get script nodes, and not other text or comment nodes $.get(JsUtils.baseUrl + "scripts/app/templates/template_compilation.html",function(data){ $templates = $(data).map(function(i, template){ return $(template); }).filter(function(){ return typeof(this.attr("id")) !== "undefined"; }); });

//memoize BasePanel.getTemplate = function(templateName){ return $templates.filter(function(){ return this.attr("id") === templateName; })[0]; //note a template call should only ever return one match, this is enforced here, and also to return the actual element and not an array of jquery elements }; };