问题
I need to require a util module in my jade template to do some checking.
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')
for a module that sits in
$ROOT/app/server/modules/queries.js
But it does not work.
Can I do what I want????
回答1:
You can register helpers from within Express.
In a request handler.
var utils = require('../../app/server/modules/queries.js')
function(req, res) {
res.render("sample", {
locals: {
title: "Welcome to Derpco",
someUtilFunction: utils.someUtilFunction
}
});
};
Also you can register helpers globally using app.locals.helpername = ...
来源:https://stackoverflow.com/questions/18407998/require-an-external-module-in-jade-in-a-node-js-webserver