【发布时间】:2012-11-12 06:54:31
【问题描述】:
我正在创建这个模板:
<% 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
有人可以帮忙吗,我根据工具箱应该一切正常
app.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'来做到这一点??
【问题讨论】:
-
你用的是什么版本的ejs和express?这看起来正确,是我使用的。 github.com/visionmedia/ejs
-
/home/justas ├── ejs@0.8.3 ├─┬ express@3.0.0