Html 如何在 Handlebar 模板中使用注释?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15336142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:19:34  来源:igfitidea点击:

How to use comments in Handlebar templates?

javascripthtmltemplateshandlebars.js

提问by Abhidev

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?

我使用 Handlebar.js 作为我的模板引擎。现在我想注释掉我车把模板中的一些块。但后来我意识到 Handlebar 不会忽略 Handlebar 注释块中的表达式。有什么解决方法吗?

回答by jptsetung

The newest version of Handlebars has block comments support :

最新版本的 Handlebars 支持块注释:

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

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

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

回答by James Hymanson

Just add an exclamation mark after the opening brackets.

只需在左括号后添加感叹号即可。

Normal Expression:

正常表达:

{{expressions}}

Commented Expression:

评论表达:

{{!expressions}}

回答by Mukesh Kumar Gupta

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.

注释不会出现在结果输出中。如果您希望显示注释,请使用 HTML 注释。

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

refer this link to

参考这个链接

回答by valavan

Use this code:

使用此代码:

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