注册自定义助手Express和HBS

我是一个完整的Node新手,请耐心等待。

我使用带有-hbs标志的快速生成器模块将默认的模板引擎切换到句柄。

我现在正在尝试注册一个自定义帮助器,允许我将页面特定的内容添加到位于布局模板中的元素。

我无法find我应该注册自定义hbs助手的地方:我试过了下面的代码(我在这里find了:“。\ node_modules \ handlebars \ dist \ cjs \ handlebars \ compiler \ helpers.js” http://www.apkapps.link/questions/2420017/handlebars-with-express-different-html-head-for-different-pages ):

function section(name, options){ if(!this._sections) this._sections = {}; this._sections[name] = options.fn(this); return null; } exports.section = section; 

但是,当我尝试从模板调用帮助器时,我得到一个“失踪的帮手:”部分“”

有人可以指出我正确的方向吗?

从把手文件,你必须注册你的帮手,

 var hbs = require('hbs'); hbs.registerHelper('helper_name', function(...) { ... }); hbs.registerPartial('partial_name', 'partial value'); 

您不需要修改“。\ node_modules \ handlebars \ dist \ cjs \ handlebars \ compiler \ helpers.js