I have to split up a string, which is delivered as JSON.
I have the following JSON output:
"title" : "Rihanna - Pon de replay"
And I need to display it like this
PON DE REPLAY
Rihanna
Right now my Handlebars template look like this:
<div>
{{#each this}}
<p>{{title}}</p>
{{/each}}
</div>
Is there someone who could help me out? I would really appreciate it! Thanks in advance...
You will need to create an helper for this.
Handlebars.registerHelper('splitTitle', function(title) {
var t = title.split(" - ");
return t[1] + " <br/> " + t[0];
});
and the tempalte should be like this,
<div>
{{#each this}}
<p>{{splitTitle title}}</p>
{{/each}}
</div>
Edit: To render HTML output, use triple curly braces {{{splitTitle title}}}
<div>
{{#each this}}
<p>{{{splitTitle title}}}</p>
{{/each}}
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With