如何在车把模板中使用{{{{raw-helper}}}} [英] How to use {{{{raw-helper}}}} in a handlebars template
本文介绍了如何在车把模板中使用{{{{raw-helper}}}}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很好的车把模板.我希望能够在其中添加以下内容:
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}}}}
但这最终会从HTML中删除整个脚本块.
but this ends up removing the entire script block from the HTML.
根据 Handlebars文档,原始块中的任何内容均应保持不变. /p>
According to the Handlebars docs anything within the raw block should be rendered untouched.
推荐答案
未内置raw-helper.注册模板后应该可以使用.
The raw-helper is not built in. After you register the template is should work.
Handlebars.registerHelper('raw', function(options) {
return options.fn(this);
});
{{{{raw}}}}
<script id="someTemplate" type="text/x-handlebars-template">
{{test}}
</script>
{{{{/raw}}}}
这篇关于如何在车把模板中使用{{{{raw-helper}}}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文