Discussions

Ask a Question
Back to All

Handlebar helper Truncate Text?

(edited)

Has anyone succeeded in using an handlebar helper that converts a full html description into a truncated plain text description?

The only thing I could find is the truncate helper:

Handlebars.registerHelper ('truncate', function (str, len) {
if (str && str.length > len && str.length > 0) {
var new_str = str + " ";
new_str = str.substr (0, len);
new_str = str.substr (0, new_str.lastIndexOf(" "));
new_str = (new_str.length > 0) ? new_str : str.substr (0, len);

    return new Handlebars.SafeString ( new_str +'...' ); 
}
return str;

});