Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在我的翡翠模板中使用一个 util 模块来进行一些检查。
我可以这样做吗?我试着跟随一个玉模板,它位于$ROOT/views/jade/sample.jade
$ROOT/views/jade/sample.jade
var utils = require('../../app/server/modules/queries.js')
对于位于
$ROOT/app/server/modules/queries.js
但它不起作用。
我可以做我想做的吗????
您可以在 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 = ...
app.locals.helpername = ...