tôi đang tạo ra mẫu này:Node.js EJS bao gồm lỗi
<% include head %>
<Placemark>
<name><%=name%></name>
<description><%=description%></description>
<Point>
<coordinates><%=coordinates%></coordinates>
</Point>
</Placemark>
<% include foot %>
Nhưng tôi luôn nhận được lỗi này:
if (!filename) throw new Error('filename option is required for includ
^
Thư mục:
[email protected]:~/node-socket.io/socket.io/examples/kml$ ls -1
app.js
foot.ejs
head.ejs
placemark.ejs
Có thể ai đó giúp đỡ, tôi theo hộp công cụ, mọi thứ sẽ hoạt động
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');
sử dụng ejs Tôi tạo mẫu, cấu trúc từ các mẫu khác. Sử dụng ejs-locals nó nói rằng nó không có phương thức render. Có cách nào để làm điều này chỉ với 'ejs' không ??
gì phiên bản của ejs và express bạn đang sử dụng? Điều này có vẻ đúng và là những gì tôi sử dụng. https://github.com/visionmedia/ejs – chovy
/home/justas ├── [email protected] ├─┬ [email protected] – sauletasmiestas