I am trying to use underscore.js in a HTML file hosted with node-express server. This file is being used to render the dynamic data on client side. Below are the codes:
in app.js:
var cons = require('consolidate');
app.engine('html', cons.underscore);
app.set('view engine', 'html');
app.locals._ = require("underscore");
in HTML:
var template = _.template($('#client-list-template').html(), {clients: response});
here "response" is a JSON
in same HTML under template script
<script id ="client-list-template", type='text/template'>
<table class="table striped">
<thead>
<tr>
<th>ID</th><th></th>
</tr>
</thead>
<tbody>
<% _.each(clients, function(client) { %>
<tr>
<td><%= client.clientID %></td>
<td><a class="btn">Edit</a></td>
</tr>
<% }); %>
</tbody>
</table>
</script>
running this code throws and error:
ReferenceError: clients is not defined
Can someone please help me understanding what is the error and how to resolve it. Same HTML when hosted in Apache server works fine.
response? it looks like it may be undefined_.templatedoesn't take two arguments. It takes one (the template) and returns a function, which itself takes one argument (the data).clientsinto the template as data?