Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Bliss Templating in express js?

I was trying what I've seen in other questions with no luck:

  • Express.js custom template engine (plate)
  • node.js + express.js + dust.js issues

I tried to override the default engine configuration with

app.register('.js.html', {
    compiler: function(str,options){...}
});

but register is undefined in express js.

I got Bliss working this way

exports.index = function(req, res){
    //res.render('index', {});
    res.send(bliss.render(__dirname+"/index",{}));
};

but I'd like to use res.render('index',output) instead.

like image 722
Jorge I. Ferreira Avatar asked Jun 05 '12 02:06

Jorge I. Ferreira


1 Answers

You have to set it up this way:

var Bliss = new require('bliss');
var bliss = new Bliss();
app.engine('.bliss',function(path,options,fn){
    fn(null,bliss.render(path, options));
});

Then you call it like this:

exports.index = function(req, res){
  res.render('user.bliss', { title: 'Express' });
};

You need a file called user.bliss under the views directory

like image 81
Raymi Avatar answered Oct 13 '22 13:10

Raymi