【发布时间】:2018-02-14 00:04:46
【问题描述】:
我正在尝试从 express 手动渲染车把模板。
//get handlebars
var hbs = require('hbs').create({
svg: require('handlebars-helper-svg'),
switch: require('../helpers/switch.js'),
case: require('../helpers/case.js'),
});
console.log(hbs)
//convert each entry to HTML via handlebars
var resultsHtml = results.map(function (tutorial) {
var template = require('../views/list-item.hbs');
template = hbs.compile(template);
return template(tutorial);
});
hbs 的日志给出了这个:
Instance {
handlebars:
{ svg: { [Function] cache: {} },
switch: [Function],
case: [Function] },
cache: {},
__express: [Function: bound middleware],
SafeString: undefined,
Utils: undefined }
这似乎有 3 个助手,但它不断吐出错误
Error: Missing helper: "svg"
除非我从模板中删除所有 SVG。
我在 app.js 中的主应用程序中使用了这个帮助程序,如下所示:
var svg = require('handlebars-helper-svg');
hbs.registerHelper('svg', svg);
但这在我的路线中不起作用,无论如何。
我做错了什么?
【问题讨论】:
标签: express handlebars.js