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

'with' statement in template function conflicts with other variables and DOM elements #71

Closed cstavro closed 13 years ago

cstavro commented 13 years ago

This update removes the with($data){ } block and instead prepends $data. in front of any render of the target property name.

In Chrome, the 'with' implementation was able to pull elements from the DOM instead of leaving the field blank if the replacement field in the template was named the same as another DOM element and there is no matching property name on the object passed into the tmpl method.

BorisMoore commented 13 years ago

Thanks cstavro. I'll take a look at this, and I agree about the issue. But I won't be getting to it for a while, as I plan to rework this aspect of jquery templates some time in March. The plan is to have a Beta2 in April, which should included considering this issue...

cstavro commented 13 years ago

Hi Boris, I just ran into an issue with my fix when it comes to nested templates. I have fixed this and committed it to my fork here but I'm new to github and not sure how to handle this. Another pull request? close this pull request and open a new one? Anyways, I realize you're not going to be getting to this immediately anyway, but just be aware of the second fix.

Thanks!

BorisMoore commented 13 years ago

Thanks cstavro. Yes I will be looking at this for Beta2. See also https://github.com/jquery/jquery-tmpl/issues#issue/14

benblank commented 13 years ago

Am I missing something? This appears to completely break the = tag:

cstavro commented 13 years ago

Admittedly I was pretty new to this when I attempted to fix that last and in all honesty I've abandoned this approach completely anyway in favour of working with the original implementation. I've simply resorted to ensuring I'm passing complete data objects with all template field values defined in the data object to ensure it is picked up in the with block properly. That being said, I still don't like the with block. I'm closing this pull request as I don't think it properly solves the problem.