简体   繁体   中英

Inline jade.render() in Express and Jade?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM