Handlebars.js原始帮助器 [英] Handlebars.js raw-helper
问题描述
我有一个很好的车把模板.我希望能够在其中添加以下内容:
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span {{#if aThing}} data-someKey="{{anotherThing}}" {{/if}}>
{{aThirdThing}}
</span>
</div>
</script>
这显然会在处理把手文件时呈现. {{}}的所有结尾都是空白,不好.我找到了
{{{{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中删除整个脚本块.
根据 Handlebars文档,原始块中的任何内容均应保持不变. /p>
我确实尝试注册了文档中提到的帮助程序,以防万一实际上并未包含该帮助程序,但这也没有帮助.
您可以躲开胡须:
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span \{{#if aThing}} data-someKey="\{{anotherThing}}" \{{/if}}>
\{{aThirdThing}}
</span>
</div>
</script>
当然不是最漂亮的解决方案,但是它可以正常工作.
I have a handlebars template that works great. I'd like to be able to put the following in it:
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span {{#if aThing}} data-someKey="{{anotherThing}}" {{/if}}>
{{aThirdThing}}
</span>
</div>
</script>
This obviously would render when the handlebars file is processed. all of the {{}}'s end up being blank, no good. I found the
{{{{raw-helper}}}}
block helper, and tried it out like so:
{{{{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}}}}
but this ends up removing the entire script block from the HTML.
According to the Handlebars docs anything within the raw block should be rendered untouched.
I did try registering the helper mentioned in the docs, just in case it wasn't actually included, but that did not help either.
You can just escape your mustaches:
<script id="someTemplate" type="text/x-handlebars-template">
<div class="editStuff">
<span \{{#if aThing}} data-someKey="\{{anotherThing}}" \{{/if}}>
\{{aThirdThing}}
</span>
</div>
</script>
Certainly not the prettiest solution but it works fine.
这篇关于Handlebars.js原始帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!