我正在创建这个模板:
<% include head %>
<Placemark>
<name><%=name%></name>
<description><%=description%></description>
<Point>
<coordinates><%=coordinates%></coordinates>
</Point>
</Placemark>
<% include foot %>
但我总是得到这个错误:
if (!filename) throw new Error('filename option is required for includ
^
目录:
justas@justas-Studio-1555:~/node-socket.io/socket.io/examples/kml$ ls -1
app.js
foot.ejs
head.ejs
placemark.ejs
有人可以帮忙吗,我根据工具箱一切都应该工作
应用程序.js:
var http = require('http');
var ejs = require('ejs');
var fs = require('fs')
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/xml'});
fs.readFile('placemark.ejs', 'utf8', function (err, template) {
var content = ejs.render(template,{
name:"test name",
description:"this is the description",
coordinates:"-122.0822035425683,37.42228990140251,0"
});
res.write(content);
res.end()
});
}).listen(8000);
console.log('Server listening at at xxxxxxxx');
使用 ejs 我渲染模板,它从其他模板构造。使用 ejs-locals 它说它没有方法渲染。有没有办法只用'ejs'来做到这一点?