html - Swig template and Node.js -
i have problem swig template , node.js.
my code:
path nodejs_swig.js file: /node
nodejs_swig.js: // __dirname /node
var http = require('http'), swig = require(__dirname + '/node_modules/swig'); swig.init({ root: '/web/public/', allowerrors: true }); console.log(swig); http.createserver(function (req, res) { var tmpl = swig.compilefile('page.html'), renderedhtml = tmpl.render({ people: [ { name: 'paul', age: 28 }, { name: 'jane', age: 26 }, { name: 'jimmy', age: 45 } ], title: 'basic example' }); res.writehead(200, { 'content-type': 'text/html' }); res.end(renderedhtml); }).listen(1337); console.log('application started on http://localhost:1337/');
html file here: /web/public
page.html file:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>{{ title }}</title> </head> <body> <h1>{{ title }}</h1> <ul> {% person in people %} <li>{{ person.name }} age {{ person.age }}</li> {% endfor %} </ul> </body> </html>
when want see result on link ip/page.html get:
{{ pagename|title }} {% author in authors %} {{ author }} {% else %} there no authors. {% endfor %}
this output see on screen.
does has idea wrong?
thanks in advance,
sorry english
Comments
Post a Comment