【发布时间】: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 得到了相同的结果......而且它在他们的沙箱中也可以这样工作。