I'm beginning to use Node.js and i've choosen my template engine, which is ejs. My app uses socket.io and on a particular request, it tries to render an ejs file and emit back to the client. The ejs file is rendered beautifully when its a single ejs file without include, but when i try to include another ejs file, it crashes with the following message: "Error: filename option is required for includes". Note, that
app.get('/', function(req, res){
res.render(__dirname+'/views/main/index',{});
});
works just fine, even if index.ejs contains <% include something %>. My other code partial, which is not working if index.ejs has include (without include it works):
io.on('connection', function(socket){
fs.readFile('/views/main/index', 'utf8', function (err, template) {
var content = ejs.render(template,{
data:data
},function(err,result){
console.log(result);
});
});
Here is a example ejs:
<% include list_header %>
<span>random content</span>