如何在小胡子模板中添加注释?

问题描述 投票:0回答:3

在我的 Mustache 模板中,我想评论几行,但我无法做到。我仍然收到以 HTML 形式显示的评论。添加评论的正确方法是什么?有人可以帮我解决这个问题吗?

这是我的代码:

<script type="text/html" id="inspector-splitViewBase">
    <div class="inspector-split-view-container flex-1 flex-fill flex-down">
        <header class='split-view-inspector-header'>
            <div class="view-title">Source Assets</div>
            {{!--  <div class="actions"> commented 
                <span class="label">Actions</span>
                <span class="gear"></span>
            </div> --}} - comment is not working
        </header>
        <div class='search-container'>
            <span class="search-icon"></span>
            <input type="text" value="" class="inspector-search" />
        </div>
        <div class="source-assets-list-container flex-1"></div>
        <footer></footer>
    </div>
</script>
handlebars.js mustache
3个回答
36
投票

Mustache 文档建议使用以下评论:

Comments begin with a bang and are ignored. The following template:
    <h1>Today{{! ignore me }}.</h1>

Will render as follows:    
    <h1>Today.</h1>

Comments may contain newlines.

我认为在你的情况下你必须使用

{{! blah }}

而不是

{{!--  blah --}}

1
投票

您正在尝试对其中也包含 html 的 Mustache 模板进行评论,因此您实际上必须在 Mustache 代码所在的位置添加 Mustache 注释,在 html 代码所在的位置添加 html 注释。

.


0
投票
{{#comment}}
... lots of stuff
{{/comment}}

您不需要以下内容,但是,如果需要,请向您的视图模型添加

comment
属性:

{
  comment: false,
  yourStuff: 'here'
}
© www.soinside.com 2019 - 2024. All rights reserved.