有没有办法将 handlebars-helpers 与 hapi 集成?
Is there a way to integrate handlebars-helpers with hapi?
我想使用 handlebars-helpers node module with my handlebars templates. I'm using hapi 作为支持车把的框架。我还没有找到任何文档或示例来说明如何使用 handlebars 作为视图引擎将 handlebars-helpers 与 hapi 结合使用。
是否可行,如果可行,解决方案是什么?
根据 hapijs api 文档的观点,我认为目前不可能:
http://hapijs.com/api#serverviewsoptions
helpersPath - the directory path where helpers are located. Helpers are functions used within templates to perform transformations and other data manipulations using the template context or other inputs. Each '.js' file in the helpers directory is loaded and the file name is used as the helper name. The files must export a single method with the signature function(context) and return a string. Sub-folders are not supported and are ignored. Defaults to no helpers support (empty path). Note that jade does not support loading helpers this way.
看起来 handlebars-helpers 的签名与 hapi
要求的不同
启动 hapi 服务器后
// hapi v17
try {
await server.start();
} catch (err) {
throw err;
}
//......
// add some handlebars helpers
let hbs = server.realm.plugins.vision.manager._engines.hbs;
// console.log('handlebars_helpers', handlebars_helpers);
if (handlebars_helpers) {
for (let key in handlebars_helpers) {
if (key) {
// console.log('key', key, helpers[key]);
hbs.module.helpers[key] = handlebars_helpers[key];
}
}
}
//check your helper is registered
// console.log('hbs.module.helpers', hbs.module.helpers);
// add some handlebars helpers
我想使用 handlebars-helpers node module with my handlebars templates. I'm using hapi 作为支持车把的框架。我还没有找到任何文档或示例来说明如何使用 handlebars 作为视图引擎将 handlebars-helpers 与 hapi 结合使用。
是否可行,如果可行,解决方案是什么?
根据 hapijs api 文档的观点,我认为目前不可能:
http://hapijs.com/api#serverviewsoptions
helpersPath - the directory path where helpers are located. Helpers are functions used within templates to perform transformations and other data manipulations using the template context or other inputs. Each '.js' file in the helpers directory is loaded and the file name is used as the helper name. The files must export a single method with the signature function(context) and return a string. Sub-folders are not supported and are ignored. Defaults to no helpers support (empty path). Note that jade does not support loading helpers this way.
看起来 handlebars-helpers 的签名与 hapi
要求的不同启动 hapi 服务器后
// hapi v17
try {
await server.start();
} catch (err) {
throw err;
}
//......
// add some handlebars helpers
let hbs = server.realm.plugins.vision.manager._engines.hbs;
// console.log('handlebars_helpers', handlebars_helpers);
if (handlebars_helpers) {
for (let key in handlebars_helpers) {
if (key) {
// console.log('key', key, helpers[key]);
hbs.module.helpers[key] = handlebars_helpers[key];
}
}
}
//check your helper is registered
// console.log('hbs.module.helpers', hbs.module.helpers);
// add some handlebars helpers