Question

I am trying to render another teams jade template using Node's Jade. The template is fairly complex and has dozens of mixins, etc. There is something like this somewhere in a mixin and I cannot make it render/compile in Express:

// ..
mixing something
    div Foo is a bar
    !{jade.render('dir/sometemplate', e)}
    // ...

Jade complains when parsing the template, that jade is undefined and therefore .render does not exist. It makes sense to me that jade is not in the locals, but how can I make this fly?

Express route (routes/index.js):

exports.index = function(req, res) {
    res.render(mod +'/module.jade', { "arg": "value, // .. JSON HERE .. } );
};

Help deeply appreciated!

Was it helpful?

Solution

You can add jade to locals quite easily:

exports.index = function(req, res) {
    res.render(mod +'/module.jade', { jade: require('jade') } );
};

But what is the point? The task above can easily be solved by an include statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top