【问题标题】:node.js handelbars Error: Missing helper: "compare"node.js 把手错误:缺少助手:“比较”
【发布时间】:2017-07-03 05:56:03
【问题描述】:

当我运行此代码以比较值是否大于 1 时,我会收到此错误

{{#compare pageCount ">" 1 }}
  <ul class="pagination"><­/ul>
    {{#compare currentPage ">" 1 }}

       <li><a href="/?page=1"> &laquo;</a></li>
    {{/compare}}

{{/compare}}

我用 node.js 安装了手把并对其进行了测试,但是当我使用比较哈希时总是出现此错误?

Error: Missing helper: "compare"
    at Object.<anonymous> (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)
    at Object.eval (eval at createFunctionContext (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23),

:8:91) 在主要(/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32) 在 ret (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12) 在 ret (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21) 在 ExpressHandlebars._renderTemplate (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/express-handlebars/lib/express-handlebars.js:247:12) 在 ExpressHandlebars。 (/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/express-handlebars/lib/express-handlebars.js:173:21)

【问题讨论】:

    标签: node.js handlebars.js


    【解决方案1】:

    您必须使用Handlebars.registerHelper 创建自定义助手,您可以查看完整的documentation 以了解如何注册自定义助手以便能够在模板中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2014-04-20
      • 2013-02-05
      相关资源
      最近更新 更多