Syntax Error with John Resig's Micro Templating.

Posted by optician on Stack Overflow See other posts from Stack Overflow or by optician
Published on 2010-04-15T22:36:36Z Indexed on 2010/04/15 22:53 UTC
Read the original article Hit count: 367

Filed under:
|
|
|
|

I'm having a bit of trouble with John Resig's Micro templating.

Can anyone help me with why it isn't working?

This is the template

<script type="text/html" id="row_tmpl">
test content {%=id%} {%=name%}
</script>

And the modified section of the engine

str
      .replace(/[\r\t\n]/g, " ")
      .split("{%").join("\t")
      .replace(/((^|%>)[^\t]*)'/g, "$1\r")
      .replace(/\t=(.*?)%>/g, "',$1,'")
      .split("\t").join("');")
      .split("%}").join("p.push('")
      .split("\r").join("\\'")
  + "');}return p.join('');");

and the javascript

var dataObject = { "id": "27", "name": "some more content" };
var html = tmpl("row_tmpl", dataObject);

and the result, as you can see =id and =name seem to be in the wrong place? Apart from changing the template syntax blocks from <% %> to {% %} I haven't changed anything.

This is from Firefox.

Error: syntax error
Line: 30, Column: 89
Source Code:
var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(' test content ');=idp.push(' ');=namep.push(' ');}return p.join('');

© Stack Overflow or respective owner

Related posts about template-engine

Related posts about JavaScript