Portable Text
Portable Text is Sanity’s rich text format that allows you to create structured content with custom blocks, annotations, and inline components. Tune Me In uses it extensively for product descriptions and editorial content.What is Portable Text?
Portable Text is a JSON-based rich text specification that:- Stores content as structured data (not HTML)
- Supports custom blocks and inline elements
- Allows embedding of products, images, and other content types
- Is framework-agnostic and portable
The PortableText Component
Tune Me In provides aPortableText component that renders Sanity’s Portable Text:
src/components/PortableText.client.jsx
Using Portable Text in Pages
Product Descriptions
Render product body content with Portable Text:Editorial Content
Custom Blocks
Portable Text supports custom block types. Here’s how Tune Me In implements them:Image Blocks
src/components/blocks/BlockImage.client.jsx
Product Blocks
src/components/blocks/BlockProduct.client.jsx
Inline Product References
One of Tune Me In’s most powerful features is inline product references that appear as interactive tooltips:src/components/blocks/BlockInlineProduct.client.jsx
Annotations (Inline Marks)
Annotations are inline marks applied to text, like links or product references.Product Annotations
Turn text into clickable product links with add-to-cart functionality:src/components/annotations/AnnotationProduct.client.jsx
Link Annotations
src/components/annotations/AnnotationLinkExternal.jsx
Creating Custom Blocks
Create the block component
Create a new component in
src/components/blocks/:src/components/blocks/BlockCallout.client.jsx
Register the block in PortableText
Add your block to the serializers:
src/components/PortableText.client.jsx
ProductsProvider Context
To access Shopify product data in Portable Text components, wrap your content withProductsProvider:
Best Practices
Keep blocks focused
Keep blocks focused
Each block component should render a single type of content. Don’t create “super blocks” that try to do too much.
Handle missing data gracefully
Handle missing data gracefully
Always check if data exists before rendering:
Style with Tailwind
Style with Tailwind
Use Tailwind utility classes for consistent styling across all blocks.
Test with different content
Test with different content
Test your blocks with various content combinations to ensure they work in all scenarios.
Next Steps
Components
Learn more about creating custom components
Styling
Style your Portable Text blocks with Tailwind CSS