我有一个效果很好的 Handlebars 模板。我希望能够将以下内容放入其中:
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span {{#if aThing}} data-someKey="{{anotherThing}}" {{/if}}>
{{aThirdThing}}
</span>
</div>
</script>
这显然会在处理 Handlebars 文件时呈现。所有的 {{}} 最终都是空白的,这不好。我找到了
{{{{raw-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 中删除整个脚本 block 。
根据Handlebars docs原始 block 中的任何内容都应保持原样。
我确实尝试注册文档中提到的帮助程序,以防万一它实际上没有包含在内,但这也没有帮助。
最佳答案
你可以逃避你的 mustache :
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span \{{#if aThing}} data-someKey="\{{anotherThing}}" \{{/if}}>
\{{aThirdThing}}
</span>
</div>
</script>
当然不是最漂亮的解决方案,但它工作得很好。
关于javascript - Handlebars.js 原始帮助程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33741905/