我使用Handlebar.js作为我的模板引擎。现在我想注释掉我的handlebar模板中的一些块。但是后来我意识到Handlebar并没有忽略Handlebar注释块中的表达式。是否有解决此问题的方法?
发布于 2013-05-27 16:19:17
最新版本的Handlebar支持块注释:
{{!-- {{commented expressions}} --}}
https://github.com/wycats/handlebars.js/commit/a927a9b0adc39660f0794b9b210c9db2f7ddecd9
发布于 2014-02-28 23:49:40
只需在左方括号后添加一个感叹号即可。
正常表达式:
{{expressions}}
注释表达式:
{{!expressions}}
发布于 2017-05-18 19:35:07
在您的handlebar模板文件中使用此方法。
<div class="entry">
{{!-- only output author name if an author exists --}}
{{#if author}}
<h1>{{author.firstName}} {{author.lastName}}</h1>
{{/if}}
</div>
注释将不会出现在结果输出中。如果您希望显示注释,则使用HTML注释。
<div class="entry">
{{! This comment will not be in the output }}
<!-- This comment will be in the output -->
</div>
https://stackoverflow.com/questions/15336142
复制相似问题