Reputation: 154
I have struggled a lot with jTemplates but I continue to fail with {#for} in Internet Explorer 7 while it works perfectly in Firefox and Chrome (not tested with other browsers).
I created a jsFiddle with a very simple test case, please can you tell why it doesn't work with IE7?
$("#result").setTemplate('Test: {$T.test} <br/>N: {#for index = 1 to 10} {$T.index} {#/for}');
$("#result").processTemplate({ "test": 3 });
The script should write
Test: 3
N: 1 2 3 4 5 6 7 8 9 10
But in IE 7 I just get
Test: 3
N:
EDIT 1:
In a real case scenario outside jsFiddle I always get a javascript error: length null or not an object, which appears to be related with jTemplates calling a jQuery get(), but while debugging with Firefox/Firebug lead me nowhere (it just works), I cannot debug properly with IE.
EDIT 2:
you can also try online at the developer website: http://jtemplates.tpython.com/ under "Live edit" with this sample code:
$("#result").setTemplate('Test: {$T.version}<br/>Ax: {#for index = 1 to 10} A{$T.index} {#/for}');
$("#result").processTemplate({"version": 4.243});
EDIT 3:
No need to enter any code, just visit jtemplates unit test with IE7 to see it FAIL
Thank you
Upvotes: 2
Views: 472
Reputation: 154
I ended up using jsRender which according to many tech blogs could be the future of client templating. I also discovered that jsRender is supported by most mobile browser (including Blackberry OS 6).
It seems that jsRender supports all functionality of jsTemplates, but the main difference is that jsRender return a string (and can be used without jQuery).
I just received a quick bugfix from the auhor of jTemplates, Tomasz Gloc, which will make me reconsider about client templating library. Here it is:
>
line 707:
oper = '{#foreach (function(i){return i;}) as ' + RegExp.$1 + ' begin=' + (RegExp.$2 || 0) + ' end=' + (RegExp.$3 || -1) + ' step=' + (RegExp.$4 || 1) + ' extData=$T}';
change to:
oper = '{#foreach TemplateUtils.LoopFunc=function(i){return i;};TemplateUtils.LoopFunc as ' + RegExp.$1 + ' begin=' + (RegExp.$2 || 0) + ' end=' + (RegExp.$3 || -1) + ' step=' + (RegExp.$4 || 1) + ' extData=$T}';
You can also back to version 0.7.8.
Soon I will release version 0.8.1 with bug fixed using other solution, but still need some tests.
Upvotes: 0