【问题标题】:Error: [search.hbs] Missing helper: "providers"错误:[search.hbs] 缺少帮助程序:“providers”
【发布时间】:2019-03-22 20:31:31
【问题描述】:

下面的代码会引发以下错误。任何帮助将不胜感激。

错误:[search.hbs] 缺少帮助程序:“providers” 在字符串。 (/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>

【问题讨论】:

    标签: express handlebars.js


    【解决方案1】:

    您的问题似乎是不言自明的:未找到提供程序助手。 我认为您的助手声明不正确。您可能会在这篇文章中找到帮助: Node / Express Handlebars - Where to define custom helpers

    【讨论】:

    • 它没有解释为什么找不到它。 app.js 是一个合法的部署位置。也就是说,您的链接很有帮助,tks
    猜你喜欢
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多