How to render doT.js templating in nodejs? How to render doT.js templating in nodejs? express express

How to render doT.js templating in nodejs?


You need to let express know to use doT as the template engine like this:

app.set("view engine", "html");app.register('.html', doT);


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:

npm install dot-emc

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:

app.engine("def", require("dot-emc").__express);app.set("view engine", "def");

Then you can start using it as you would any other view engine in your routes, e.g.:

app.get("/", function(req, res) {    res.render("index", {"title": "title goes here"});});


If you're running express 3, it's not supported yet. You can however use express-dot:

npm install express-dot

Then in configure

app.set('view engine', 'dot' );app.engine('dot', require('express-dot').__express );

Then in routes:

res.render('profile', {}); // you will need to create views/profile.dot