jquery-tmpl icon indicating copy to clipboard operation
jquery-tmpl copied to clipboard

{{if expr}} can error for certain expressions, or lead to repeated evaluation of expression.

Open dvv opened this issue 15 years ago • 4 comments

Hi!

I discovered the source of constant ReferenceError being thrown in my templates: $.tmpl('{{if !user}}NOUSER{{/if}}', {}), though $.tmpl('{{if user}}USER{{/if}}', {}) works silently.

In the guts the first version compiles to ... if((typeof((!user))!=='undefined' && ((!user))!=null) && ... which of course requires user to be in the scope.

Couldn't we fix that (quite valid) case of branching, or at least put big fat warning on templates usage pattern?

TIA, --Vladimir

dvv avatar Oct 21 '10 06:10 dvv

Relates to https://github.com/jquery/jquery-tmpl/issues#issue/21.

BorisMoore avatar Nov 19 '10 19:11 BorisMoore

{{if (!isEnabled())}} will work. But {{if false==isEnabled()}} will fail!

So yes, there are indeed some issues around automatic detection of null/undefined, and type function, for expression in {{if expression}}. We will be working on improvements in this area... See also issue 35

BorisMoore avatar Dec 27 '10 20:12 BorisMoore

See also related issue https://github.com/jquery/jquery-tmpl/issues#issue/40 and https://github.com/jquery/jquery-tmpl/issues/issue/41

BorisMoore avatar Jan 06 '11 19:01 BorisMoore

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.

rdworth avatar Oct 08 '11 06:10 rdworth