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

How to use a Custom Preview Component on the Document View

15 replies
Last updated: Apr 21, 2020
how do I use a custom preview component on the document view?
Apr 21, 2020, 5:46 PM
say i have an document
video
that i want to show the video preview on the document view
i also reference this video in another document, but when its a reference, I only want to show the
video
document title
how is this accomplished?
Apr 21, 2020, 5:47 PM
Just to confirm I’m understanding fully, you have a custom preview component for your
video
document type, e.g. something like on https://www.sanity.io/guides/portable-text-how-to-add-a-custom-youtube-embed-block . You’re happy to show this preview in
video
, but when you add a reference to the document type you don’t want to see it. Is that correct? What kind of preview does the reference currently show?
Apr 21, 2020, 6:05 PM
yes...
Apr 21, 2020, 6:12 PM
here's some screens
Apr 21, 2020, 6:12 PM
Video document... would like the preview here
Apr 21, 2020, 6:13 PM
When referenced ... this is fine
Apr 21, 2020, 6:13 PM
the reason the reference looks ok, is because I removed the
preview
from the schema, otherwise it was trying to load the videoPreview component
Apr 21, 2020, 6:14 PM
Thanks for the shots, always helps! 🙂 Have you considered adding a video object to your video document (under a different name)? That should let you show the preview on the document but just the title in the reference 📽️
This would require loading the preview component in the object instead.
Apr 21, 2020, 6:53 PM
i had not considered that ... so making a
video
object that goes inside the
video
document. does the object only contain the URL for the video? (i'm sourcing from vimeo)
Apr 21, 2020, 7:50 PM
Yep, I’d say so, unless you want to add more data that specifically belongs to the video like a title or caption etc.
Apr 21, 2020, 7:54 PM
well, i would think i could just use the
document
title... since the document is really about the video
Apr 21, 2020, 7:55 PM
One thing you could consider is whether you need that kind of data in the document where you reference the video.
Apr 21, 2020, 8:05 PM
been thinking the same thing ...
Apr 21, 2020, 8:06 PM
99% of the time, i'm probably also the document editor, and i'll know the video already
Apr 21, 2020, 8:06 PM
however, i do see a scenario down the road where I use this dataset as a source for another Sanity project, and the people using that project will need a visual reference to what the video looks like
Apr 21, 2020, 8:07 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?