0

I am using the SharePoint modern search results web part.

I am trying to truncate the Description variable so it only shows 50 characters.

{{Description.substring(0, 50)}}
{{Description.slice(0, 50)}}

I would have thought that would work as it's using JS right?

Can any body please point me in the right direction?

Is this where the helper goes? enter image description here

1 Answer 1

1

You need to create a custom handlebar helper to truncate the string.

Example:

public registerHandlebarsCustomizations(namespace: typeof Handlebars) {
    namespace.registerHelper('trimString', function(passedString, startstring, endstring) {
        var theString = passedString.substring( startstring, endstring );
        return new namespace.SafeString(theString)
    });
}

Then, in template, you can use it like:

<p>{{{trimString value 0 50}}}</p>

References:

  1. Register Handlebars customizations
  2. Handlebars - substring
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.