问题
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.
回答1:
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}}}}
来源:https://stackoverflow.com/questions/33704495/how-to-use-raw-helper-in-a-handlebars-template