【问题标题】:Handlebars.js raw-helperHandlebars.js 原始助手
【发布时间】:2016-02-17 22:28:43
【问题描述】:

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

<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,原始块中的任何内容都应保持不变。

我确实尝试注册文档中提到的帮助程序,以防它实际上没有被包含在内,但这也没有帮助。

【问题讨论】:

  • 我不确定原始助手是否会在这里为您提供帮助,您能否将发送的数据添加到模板中?有什么问题吗?
  • 我发送给它的数据是无关紧要的 - 在模板文件最初预编译后没有 {{places}} 可以放置它。 raw-helper 不会阻止预编译器处理其块的内容。上述块的输出应该是原始助手块的当前内容,{{}} 完好无损,可以在我的代码中编译和使用。
  • 我使用 run-helper 得到了相同的结果......而且它在他们的沙箱中也可以这样工作。

标签: javascript handlebars.js


【解决方案1】:

你可以摆脱你的胡子:

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

当然不是最漂亮的解决方案,但效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多