sanity icon indicating copy to clipboard operation
sanity copied to clipboard

How do I render block children with custom containers?

Open toddpadwick opened this issue 2 years ago • 2 comments

I have a sanity Block content field that contains:

  • General text styling
  • Gallery component
  • banner component
  • video component

I would like to wrap chunks of block text in a different container tag to the other components so that I can apply styling to it that doesn't effect the components. such as max widths, or wrapping in a box or similar. How can I specify a container tag for specific children of the block serialiser?

toddpadwick avatar Apr 08 '23 17:04 toddpadwick

Are you using portable text in the studio? If so create custom blocks and add a serializer in the frontend to render the blocks how you like.

Or create styles for the tags you like and create the serializer for that too. You can render a custom component for each style of block you add.

https://www.sanity.io/docs/portable-text-editor-configuration#dde2a7a4c661 https://www.sanity.io/docs/portable-text-editor-configuration#8997d6860827

procrates avatar Apr 25 '23 13:04 procrates