How to split and slice a string in Handlebars?
To split and slice a string in Handlebars; you need to register a custom helper for Handlebars. There is an example about how to register a custom helper for Handlebars in official Handlebars website https://handlebarsjs.com/#helpers
This is my custom helper
Handlebars.registerHelper('splitUrl', function(url) {return url.split("/").slice(-1,str.length);});
Which splits the url string
var url = "https://twitter.com/akarshseggemu";
and slices it to return only the last part i.e. my username “akarshseggemu”.
You can use the custom helper in the hbs file like this
<p>{{splitUrl url}}</p>
If you like my articles please follow me. You can also support me by https://www.buymeacoffee.com/akarshseggemu