面搜索给我带来了问题,当面名包含特殊字符时--特别是/
、(
和)
。我正在尝试使用内置在模板中的车把助手来替换特殊的字符。每当我使用replace
车把助手时,我都会得到500个错误。
国家预防机制的文件示例:
{{replace "Liquid Snake" "Liquid" "Solid"}}
即使使用精确的代码(简单字符串,而不是变量),我也得到了500错误。
这是日志:
Debug: internal, implementation, error
TypeError: Uncaught error: options.inverse is not a function
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/helpers/replace.js:19:28)
at Object.template.1 (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/index.js:71:44), <anonymous>:11:72)
at Object.prog [as fn] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:193:15)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/helpers/if.js:85:28)
at Object.template.main (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/index.js:71:44), <anonymous>:70:35)
at Object.ret [as components/faceted-search/facets/multi] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:159:30)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/helpers/dynamicComponent.js:32:50)
at Object.template.7 (eval at <anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/index.js:71:44), <anonymous>:33:109)
at Object.prog [as fn] (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/handlebars/dist/cjs/handlebars/runtime.js:193:15)
at Object.<anonymous> (/Users/theuser/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/@bigcommerce/stencil-paper/helpers/if.js:85:28)
发布于 2016-06-18 17:55:58
我认为您正在查找错误的replace
助手的文档。您使用的助手库来自BigCommerce,其replace
助手是车把,块状帮手。使用它的方法是:
{{#replace "Liquid" "Liquid Snake"}}Solid{{/replace}}
编辑
感谢您指出,我在示例中错误地将替换字符串封装在胡子括号中。我已经在我的原始代码块中用{{"Solid"}}
替换了Solid
,所以这个示例现在是正确的。
至于您的后续工作,当要替换的字符串(指针)没有在目标字符串(干草堆)中找到时,没有输出:原来这是助手的设计行为。我已经检查了源代码,并且可以确认它实现了以下规则:
else
分支。这意味着,如果我们想要显示任何输出,比如原始的干草堆,当干草堆中没有匹配的针头时,我们必须使用模板中的其他分支来显示:
{{#replace "Liquid" "Liquid Snake"}}Solid{{else}}Liquid Snake{{/replace}}
老实说,这看起来确实是这个助手的一个相当尴尬的实现。
https://stackoverflow.com/questions/36801592
复制相似问题