How to use comments in Handlebar templates?

帅比萌擦擦* 提交于 2019-12-20 08:41:46

问题


I am using Handlebar.js as my templating engine. Now I want to comment out some of the blocks in my handlebar templates. But then I realized that Handlebar doesn't ignore the expressions inside the Handlebar comment block. Any workaround for this?


回答1:


The newest version of Handlebars has block comments support :

{{!-- {{commented expressions}} --}}

https://github.com/wycats/handlebars.js/commit/a927a9b0adc39660f0794b9b210c9db2f7ddecd9




回答2:


Just add an exclamation mark after the opening brackets.

Normal Expression:

{{expressions}}

Commented Expression:

{{!expressions}}



回答3:


Use this way in your handlebar template file.

<div class="entry">
  {{!-- only output author name if an author exists --}}
  {{#if author}}
    <h1>{{author.firstName}} {{author.lastName}}</h1>
  {{/if}}
</div>

The comments will not be in the resulting output. If you'd like the comments to show up, then use HTML comments.

<div class="entry">
  {{! This comment will not be in the output }}
  <!-- This comment will be in the output -->
</div>

refer this link to




回答4:


Use this code:

{{#data}}
<!-- enter comments here  -->
<p>{{name}}</p>
{{/data}}  


来源:https://stackoverflow.com/questions/15336142/how-to-use-comments-in-handlebar-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!