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

A template with no html tag returns an empty string ? #125

Closed rnaud closed 13 years ago

rnaud commented 13 years ago

Hello, I have a slight problem with using the template plugin with no html content

$.template("url", "https://${email}:${apiKey}@${host}/${path}");
$.tmpl( "url", {email:"user@email.com", apiKey: "32323232", host: "exaple.com", path: "app/api"});
returns []

$.template("url", "<li>https://${email}:${apiKey}@${host}/${path}</li>");
$.tmpl( "url", {email:"user@email.com", apiKey: "32323232", host: "exaple.com", path: "app/api"});
returns [<li>​https://user@email.com:32323232@exaple.com/app/api​</li>​]

Am I doing something wrong ? Is there any config I should change to avoid that ?

BorisMoore commented 13 years ago

It should return a jQuery object, ret, wrapping a single text node, so ret.text() = "https://user@email.com:32323232@exaple.com/app/api"

However jQuery objects wrapping only text nodes are not really reliable. jQuery does not provide real support for wrapping content that starts or ends with a text node. Outer text nodes are sometimes stripped, to trying to chain with appendTo or similar will probably not work. JsRender is the future version of jQuery templates which will provide full support for rendering strings, and having templates with no HTML content. See also JsViews .