【问题标题】:How to use {{{{raw-helper}}}} in a handlebars template如何在车把模板中使用 {{{{raw-helper}}}}
【发布时间】:2015-11-14 02:25:51
【问题描述】:

我有一个很好用的车把模板。我希望能够将以下内容放入其中:

<script id="someTemplate" type="text/x-handlebars-template">
    <div class="editStuff">
        <span {{#if aThing}} data-someKey="{{anotherThing}}" {{/if}}>
            {{aThirdThing}}
        </span>
    </div>
</script>

这显然会在处理车把文件时呈现。所有的 {{}} 最终都是空白的,不好。我找到了

{{{{raw-helper}}}}

block helper,并尝试如下:

{{{{raw-helper}}}}
<script id="someTemplate" type="text/x-handlebars-template">
    <div class="editStuff">
        <span {{#if aThing}} data-addresskey="{{anotherThing}}" {{/if}}>
            {{aThirdThing}}
        </span>
    </div>
</script>
{{{{/raw-helper}}}}

但这最终会从 HTML 中删除整个脚本块。

根据Handlebars docs,原始块中的任何内容都应保持不变。

【问题讨论】:

  • 以防万一这不是内置帮助程序,我还尝试在文档页面的示例中注册处理程序。不好。很难判断车把 API 中包含和未包含的内容。

标签: javascript handlebars.js


【解决方案1】:

raw-helper 没有内置。注册后模板应该可以工作。

Handlebars.registerHelper('raw', function(options) {
  return options.fn(this);
});

{{{{raw}}}}
<script id="someTemplate" type="text/x-handlebars-template">
    {{test}}
</script>
{{{{/raw}}}}

【讨论】:

  • 为什么没有内置?在文档中提及它似乎很愚蠢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
相关资源
最近更新 更多