下面的代码引发以下错误。任何帮助将不胜感激。
错误:[search.hbs]缺少帮助者:“提供者” 在String。 (/Users/me/cs-conn/node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)
在app.js中
import hbs from 'express-hbs';
import routes from './routes';
const app = express();
const addon = ace(app);
const viewsDir = __dirname + '/views';
app.engine('hbs', hbs.express4({partialsDir: viewsDir}));
app.set('view engine', 'hbs');
app.set('views', viewsDir);
routes(app, addon);
hbs.registerHelper('providers', function(object) {
console.log("== " + JSON.stringify(object))
var result =""
if (object === undefined){
} else {
result = object.providers
}
console.log("\nresult\n" + result)
return result
});
// Boot the HTTP server
http.createServer(app).listen(port, () => {
console.log('App server running at http://' + os.hostname() + ':' + port);
// Enables auto registration/de-registration of app into a host in dev mode
if (devEnv) addon.register();
});
hbs模板
{{#if search_results includeZero=true}}
<div>
{{#each meta_results.indices_original}}
<a href="/search?search={{../search_criteria}}&indexname={{@key}}&providers={{{providers ../meta_results}}}&indices_original={{{all_indices ../meta_results}}}"> Search only {{this}} </a><br>
{{/each}}
</div>
{{/if}}</td></tr>
</table>
答案 0 :(得分:0)
您的问题似乎是不言而喻的:找不到提供程序帮助程序。 我认为您对助手的声明不正确。您可能会在此职位上找到帮助: Node / Express Handlebars - Where to define custom helpers