当我运行此代码以比较值时,如果它大于1我得到此错误
{{#compare pageCount ">" 1 }}
<ul class="pagination"></ul>
{{#compare currentPage ">" 1 }}
<li><a href="/?page=1"> «</a></li>
{{/compare}}
{{/compare}}
我用node.js安装了handelbars并测试了它但是当我使用比较哈希时我总是得到这个错误?
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) 在main(/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32) at ret(/opt/lampp/htdocs/x/chessMult/regtest/using-passport-with-sequelize-and-mysql-master/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12) at 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)
答案 0 :(得分:2)
您必须使用Handlebars.registerHelper
创建自定义帮助程序,您可以检查完整的documentation以了解如何注册自定义帮助程序以便能够在模板中使用它。