我使用 Express-Handlebars 并想重构此代码示例以分隔文件
const express = require('express');
const exphbs = require('express-handlebars');
const handlebars = exphbs.create({
defaultLayout: 'index',
extname: 'hbs',
helpers: {
foo: function () { // first helper
return 'FOO!';
},
bar: function () { // second helper
return 'BAR!';
}
//, nth helper ...
}
});
原因是为什么要将所有 HTML 逻辑放入app.js
文件中。我想为 1 个助手提供 1 个文件。
如何从外部文件注册助手?有人可以给我一个例子吗?