I have a problem with swig template and node.js.
My code:
path where is nodejs_swig.js file: /node
nodejs_swig.js: // __dirname is /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 is here: /web/public
page.html file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
<ul>
{% for person in people %}
<li>{{ person.name }} age {{ person.age }}</li>
{% endfor %}
</ul>
</body>
</html>
when i want to see the result on link ip/page.html i get:
{{ pagename|title }}
{% for author in authors %} {{ author }} {% else %}
There are no authors.
{% endfor %}
this is my output which i see on screen.
Does anyone has any idea what is wrong?
Thanks in advance,
sorry for my english