The following code returns an error "Uncaught ReferenceError: size is not defined" in Chrome if variable size is not defined:
<script type="text/x-jquery-tmpl">
{{if name && size}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
</script>
While this code works fine :
<script type="text/x-jquery-tmpl">
{{if name}}
{{if size}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
{{/if}}
</script>
Can I somehow make it work in Chrome without using double if statement and why does it return an error at all?
The following code returns an error "Uncaught ReferenceError: size is not defined" in Chrome if variable size is not defined:
<script type="text/x-jquery-tmpl">
{{if name && size}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
</script>
While this code works fine :
<script type="text/x-jquery-tmpl">
{{if name}}
{{if size}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
{{/if}}
</script>
Can I somehow make it work in Chrome without using double if statement and why does it return an error at all?
Share Improve this question asked Sep 11, 2012 at 9:29 bogatyrjovbogatyrjov 5,3789 gold badges38 silver badges61 bronze badges 3-
Have you tried
{{ if (name && size) }}
? – alexbusu Commented Sep 11, 2012 at 9:32 -
Post your object, maybe the object doesn't contain
size
orsize
is in other level than withname
. – Snake Eyes Commented Sep 11, 2012 at 9:32 - Alexander, yes, i've tried. Snake Eyes, the object doesn't contain size. The if statement is there to check it. – bogatyrjov Commented Sep 11, 2012 at 13:00
2 Answers
Reset to default 4try this:
<script type="text/x-jquery-tmpl">
{{if name && size != null && size}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
</script>
Try this
<script type="text/x-jquery-tmpl">
{{if (name != null && size != null)}}
<p>${name}</p>
<p>${size}</p>
{{/if}}
</script>
Note the space after if statement.