Reputation: 1677
From my REST API, I am passing in certain strings where white space is replaced by a white space.
When it comes to the handlebars component, I would like to replace these back with whitespace before it is displayed in the browser.
How can I replace a part of a string, white space, in this case, with inside of the handlebars.
This is my code
<html>
<head>
<table>
<thead>
</thead>
<tbody>
{{#goalSetValues}}
<td><button onclick=init('{{goal}}')>{{goal}}</button></td>
{{/goalSetValues}}
</tbody>
</table>
<script type="text/javascript">
function init (goalName) {
console.log('came inside the init function with goalName == ' + goalName)
}
</script>
</head>
</html>
I have tried a couple of things,
<td><button onclick=init('{{goal}}')>{{replace goal " " " "}}</button></td>
and
<td><button onclick=init('{{goal}}')>{{#replace " " " "}}{{goal}}{{/replace}}</button></td>
However, they do not seem to work. Please advise me.
Upvotes: 2
Views: 4299
Reputation: 1004
Use triple brackets: {{{}}}
to output as raw HTML.
Then the
will automatically be rendered as whitespace by the browser.
E.g.
<td><button onclick=init('{{{goal}}}')>{{{goal}}}</button></td>
Upvotes: 2
Reputation: 103
You could parse your goalSetValues array in such a way so as to replace the "  ;" in your string with an actual non breaking space.
var string = "Hello World";
var nbsp = String.fromCharCode(parseInt("00A0", 16));
string = string.replace(" ", nbsp);
This will make the string "Hello World" but the space you see is actually a non breaking space.
Upvotes: 0