Truncate articles to the nearest sentence

I am working with an articles content type. Per usual, there is a content field that stores the body of the article. On a page that links to the articles, I want to display the first paragraph. I am familiar with the truncate to operators. Those are limited to choose a specific number of characters from what I see.

How would I try and grab for example, the first 3 sentences from a post?

That way I could display the summary automatically and not deal with unfinished sentences/clipped words.

Reviewed docs before posting, here is the operator that I mentioned:

Hi there, @mc3digital… this suggestion may not work all that well depending on the length of the sentences, but to grab the first 3 sentences from a post, you could use the :split by operator to split by a period, and then grab the first 3 items from the split using the :items until # operator. Want to give that a try?



Just gave it a shot. It nearly works already…
Parent group's Article's body:split by (.):items until #2
Result is:
Sentence 1, Sentence 2

Fine tuning the idea…
Going to have to use an expression per sentence, then manually add the period as text.

1 Like

Complementing what @mikeloc suggested…

As we may have more then one final point type, like “exclamation” and “question marks”, I suggest you to perform a :find and replace of your entire text doing the fallow replacements:

. → #
! → #
? → #

  1. Now you can :split your text by #
  2. Use :Items unitil 3:Number of chacacters to know the length of these 3 first sentences
  3. Use the :truncated to to grab only the first 3 sentences

Make sense?


Oh, right, sorry… I forgot that the split by character gets removed.

1 Like

You set me on the right track to sorting this out! It took me a second to realize what was happening when I was looking for the 2 sentences and it had been converted into one run-on sentence…

I have a nice display now. Here is how I set it up:
Parent group's Article's body:split by (.):item #1. Parent group's Article's body:split by (.):item #2.

@rpetribu Thank you for looking into this as well. I like the idea, and may implement this in the future. It is always interesting to consider alternate ways to solve the problem and I see this approach is more flexible as well.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.