I'm trying to use underscore templates BOTH on the server and browser, but the browser-side is not working.
I'm using _.templates on the server side when the page is rendered, with the default template delimiters <% %>
I am also trying to use them browser-side, in this case changing the templating delimiters
Here's the code:
_.templateSettings = { //use mustache style on browser
interpolate : /\{\{(.+?)\}\}/g
};
var compile=_.template($('#friend_row').html());
var result=compile({hello: 'hello world'});
In the html body I defined the following template:
<script id="friend_row" type="text/template">
{{=hello}}
</script>
This generates the error:
SyntaxError: syntax error [Break On This Error]
((_t=(=hello))==null?'':_t)+
underscore-min.js (line 4, col 7)
{{=hello}} is an invalid expression. What goes inside the braces has to be a valid javascript expression, and that is not. You want just {{hello}}.