BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

'else if' doesn't work in IE8 #65

Closed sandord closed 12 years ago

sandord commented 12 years ago

In IE8 I the following template throws an exception in IE8 (expected identifier, line 552 in jsrender.js):

<td class="status {{#if Sold}}sold{{else if Pending}}pending{{else if Vacant}}vacant{{/if}}"></td>

Writing it like this does work though:

<td class="status {{#if Sold}}sold{{/if}}{{#if Pending}}pending{{/if}}{{#if Vacant}}vacant{{/if}}"></td>
BorisMoore commented 12 years ago

This is because you are using the wrong syntax. {{else}} is a tag. There is no 'else if' syntax. The correct syntax is:

{{#if Sold}}sold{{else Pending}}pending{{else Vacant}}vacant{{/if}
sandord commented 12 years ago

Thanks, my bad. It's strange though that only IE8 bails out on that code, not IE9, FF9 or Chrome...

BorisMoore commented 12 years ago

It is because {{else if Pending}} will treat 'if' as another data property - so it becomes (in code) else if(data.if || data.Pending). data.if is not supported in IE8 (it requires you to write data["if"] - because if is a key word. In IE9, Chrome, etc. keywords are accepted, so data.if will have a value undefined, but will not throw...

sandord commented 12 years ago

Ah, that makes a lot of sense. Thanks for explaining.

BorisMoore commented 11 years ago

There will be a specific error message for this, coming up in the next commit...