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 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.
Share Improve this question asked Nov 14, 2015 at 2:25 Dakine83Dakine83 7072 gold badges9 silver badges23 bronze badges 1- 1 Just in case this was not a built in helper, I also tried registering the handler in the sample on the docs page. No good. It's pretty difficult to tell what is and isn't baked in on the handlebars API. – Dakine83 Commented Nov 14, 2015 at 2:39
2 Answers
Reset to default 8The 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}}}}
To avoid escaping HTML you can use triple curly brackets {{{
like this:
<span>{{{content with HTML here}}}</span>
More info here: https://handlebarsjs./guide/expressions.html#html-escaping