Hi I would like to know how can I render output in dot.js templating engine. I think it's a generic question about nodejs templating.(read comments for more info). The reason why I chose this template engine instead of jade or ejs is because it seems the fastest engine around.
Here is my app.js:
var express = require('express'),
app = express.createServer(),
doT = require('doT'),
pub = __dirname + '/public',
view = __dirname + '/views';
app.configure(function(){
app.set('views', view);
app.set('view options', {layout: false});
app.set('view engine', 'dot');
app.use(app.router);
});
app.register('.html', {
compile: function(str, opts){
return function(locals){
return str;
}
}
});
app.get('/', function(req, res){
//This is where I am trying to send data to the front end....
res.render('index.html', { output: 'someStuff' });
});
Here is my html:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Index</title>
</head>
<body>
//This is where I am trying to receive data and output it...
{{=it.output}}
</body>
</html>
I just could not find good docs on it. This was not enough: http://olado.github.com/doT/. Please help, if you can. This will improve my understanding exponentially of how data is passed to the view in nodejs. Thank you.
My post is a shameless plug, but it might help someone out.
I wasn't very happy with the way existing modules worked with Express 3.x, I wrote one called dot-emc:
https://github.com/nerdo/dot-emc
Usage is similar to what has been posted above. Install it with nom:
Then set it up as your default view engine. I prefer using the .def extension since my text editor recognizes .dot files as Graphviz files, so the syntax is slightly different:
Then you can start using it as you would any other view engine in your routes, e.g.:
I know this is an old question, but I recently wanted to test doT with a standard generated Express 4.x.x app. I did not find the express example from @olado to match easy with my generated app. I tried different plugins (getting it to work, but not satisfied), so I ended up writing the template engine like this in order to get pre-compiled dot files with support for includes(#) without any extra plugin:
Now I can use it in the standard "res.render" way in the routes like this (for index.js):
Remember to use {{it.value}} in the .dot template files. In basic example above, the index.dot would look something like this:
You need to let express know to use doT as the template engine like this:
If you're running express 3, it's not supported yet. You can however use express-dot:
npm install express-dot
Then in configure
Then in routes: