我創建這個模板:node.js的EJS包括錯誤
<% 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
^
目錄:
[email protected]:~/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嗎?這看起來是正確的,是我使用的。 https://github.com/visionmedia/ejs – chovy
/home/justas ├──[email protected] ├─┬[email protected] – sauletasmiestas