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

About ${attr} and ${$item.data.attr} #164

Closed kevin-lyn closed 9 years ago

kevin-lyn commented 12 years ago

I use:

<p>${content}</p>

and I found that if "content" is an empty string or undefined, jqtmpl would continue to find the parent scope chain until global scope. And I found this in firefox when "content" is an empty, and it shows [object Window].

Instead of, I use:

<p>${$item.data.content}<p>

every thing is expected.

Is this a bug?

sheelasurisetty commented 12 years ago

So, I edited the function buildTmplFn on 342 in tmpl.js and changed the following code: In buildTmplFn changed Line1 below with Line2 below: .replace( /\${([^}])}/g, "{{= $1}}" ) --> Line1 .replace( /\${([^}])}/g, "{{= \$item.data.$1}}" ) -->Line2 which fixed the problem. I hope this helps!