简体   繁体   English

在Express和Jade中内联jade.render()?

[英]Inline jade.render() in Express and Jade?

I am trying to render another teams jade template using Node's Jade. 我正在尝试使用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: 该模板非常复杂,并且包含数十个mixin,等等。mixin中的某处类似这样,我无法在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. Jade在解析模板时抱怨说jade是未定义的,因此.render不存在。 It makes sense to me that jade is not in the locals, but how can I make this fly? 对我来说,翡翠不在当地人是有意义的,但是我该如何使它飞起来呢?

Express route (routes/index.js): 快速路由(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. 上面的任务可以很容易地通过include语句解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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