“ handlebars.registerHelper不是函数”

时间:2018-11-19 18:43:30

标签: node.js handlebars.js

我想创建一个简单的反向车把助手,但是在app.js运行时,出现此错误:

TypeError: exphbs.registerHelper is not a function
at Object.<anonymous> (C:\wamp64\www\test\login\server\example.js:7:8)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)

非常感谢 内森

1 个答案:

答案 0 :(得分:0)

假设以下内容:

const exphbs = require('exphbs');

要手动注册助手,请使用以下方法:

const handlebars = exphbs.handlebars;

handlebars.registerHelper('hello', function() {
  return new handlebars.SafeString('Hello!');
});

来自the fine manual