jquery-tmpl
jquery-tmpl copied to clipboard
{{if expr}} can error for certain expressions, or lead to repeated evaluation of expression.
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
Relates to https://github.com/jquery/jquery-tmpl/issues#issue/21.
{{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
See also related issue https://github.com/jquery/jquery-tmpl/issues#issue/40 and https://github.com/jquery/jquery-tmpl/issues/issue/41
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.