Abh*_*dev 130 html javascript templates handlebars.js
我使用Handlebar.js作为我的模板引擎.现在我想在我的车把模板中注释掉一些块.但后来我意识到Handlebar不会忽略Handlebar注释块中的表达式.有什么解决方法吗?
jpt*_*ung 187
最新版本的Handlebars具有块注释支持:
{{!-- {{commented expressions}} --}}
Run Code Online (Sandbox Code Playgroud)
https://github.com/wycats/handlebars.js/commit/a927a9b0adc39660f0794b9b210c9db2f7ddecd9
小智 50
只需在左括号后添加感叹号即可.
正常表达:
{{expressions}}
Run Code Online (Sandbox Code Playgroud)
评论表达:
{{!expressions}}
Run Code Online (Sandbox Code Playgroud)
Muk*_*pta 27
在车把模板文件中使用这种方式.
<div class="entry">
{{!-- only output author name if an author exists --}}
{{#if author}}
<h1>{{author.firstName}} {{author.lastName}}</h1>
{{/if}}
</div>
Run Code Online (Sandbox Code Playgroud)
注释不会出现在结果输出中.如果您希望显示评论,请使用HTML评论.
<div class="entry">
{{! This comment will not be in the output }}
<!-- This comment will be in the output -->
</div>
Run Code Online (Sandbox Code Playgroud)