私はこのテンプレートを作成しています:
<% 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を使用すると、renderメソッドがないことがわかります。'ejs'だけでこれを行う方法はありますか?