Here is a underscore template whose chances to work within a Asp.net page are weak. Since <%
is understood as opening tag for asp.net
( MVC
and WebForm
) code, can someone tell me how do I insert the following code in a asp.net page?
<script type="text/html" id='div-data'>
<% _.each(items,function(item,key,list){ %>
<div><%= key %></div>
<div><%= item.name %></div>
<% }) %>
</script>
Almost solved! I'd like to post this answer because It may help others...
I had to configure underscore
to tell him that he must escape the asp.net render function <% %>
_.templateSettings = {
interpolate: /\{%=(.+?)%\}/g,
escape: /\{%-(.+?)%\}/g,
evaluate: /\{%(.+?)%\}/g
};
Now I can use {% %}
instead.
Thank you