👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

How to get the First Paragraph from BlockContent

7 replies
Last updated: May 5, 2021
Hi, Is it possible to get the first paragraph (or so) from a BlockContent? Would it be a query? or a custom serializer? Trying to create a “preview” section for blog posts. Thanks
May 5, 2021, 9:04 PM
block content is an array of rich text elements (and custom types), so you can get the first 3 or so blocks
May 5, 2021, 9:08 PM
i did something similar by splicing the array on my frontend
May 5, 2021, 9:09 PM
you could also create your own element that acts as a stopping point for the preview and just render until that specific element, showing instead a [read more] button or whatever 😄
May 5, 2021, 9:11 PM
block content is an array of rich text elements (and custom types), so you can get the first 3 or so blocks
May 5, 2021, 9:08 PM
we are using typescript so will try the query solution first, see if I can pull back just the first block
May 5, 2021, 9:24 PM
ooh good idea on a breaking element! Would look nice in the CMS
Some intro text

[ Break text here! ]

The rest
May 5, 2021, 9:26 PM
thanks
user A
! beautiful solution!
May 5, 2021, 10:25 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?