需要在node.js Web服务器的Jade中使用外部模块 [英] require an external module in jade in a node.js webserver
本文介绍了需要在node.js Web服务器的Jade中使用外部模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的Jade模板中要求一个util模块进行检查.
I need to require a util module in my jade template to do some checking.
我可以这样做吗?我尝试过在$ROOT/views/jade/sample.jade
Can I do that? I tried following in a jade template which sits in $ROOT/views/jade/sample.jade
var utils = require('../../app/server/modules/queries.js')
对于位于
$ROOT/app/server/modules/queries.js
但是它不起作用.
我可以做我想做的吗??
Can I do what I want????
推荐答案
您可以在Express中注册帮助程序.
You can register helpers from within Express.
在请求处理程序中.
var utils = require('../../app/server/modules/queries.js')
function(req, res) {
res.render("sample", {
locals: {
title: "Welcome to Derpco",
someUtilFunction: utils.someUtilFunction
}
});
};
您还可以使用app.locals.helpername = ...
这篇关于需要在node.js Web服务器的Jade中使用外部模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文