How to use a Custom Preview Component on the Document View
15 replies
Last updated: Apr 21, 2020
B
how do I use a custom preview component on the document view?
Apr 21, 2020, 5:46 PM
B
say i have an document
i also reference this video in another document, but when its a reference, I only want to show the
how is this accomplished?
videothat 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
videodocument title
how is this accomplished?
Apr 21, 2020, 5:47 PM
P
Just to confirm I’m understanding fully, you have a custom preview component for your
videodocument 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
B
yes...
Apr 21, 2020, 6:12 PM
B
here's some screens
Apr 21, 2020, 6:12 PM
B
Video document... would like the preview here
Apr 21, 2020, 6:13 PM
B
When referenced ... this is fine
Apr 21, 2020, 6:13 PM
B
the reason the reference looks ok, is because I removed the
previewfrom the schema, otherwise it was trying to load the videoPreview component
Apr 21, 2020, 6:14 PM
P
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.
This would require loading the preview component in the object instead.
Apr 21, 2020, 6:53 PM
B
i had not considered that ... so making a
videoobject that goes inside the
videodocument. does the object only contain the URL for the video? (i'm sourcing from vimeo)
Apr 21, 2020, 7:50 PM
P
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
B
well, i would think i could just use the
documenttitle... since the document is really about the video
Apr 21, 2020, 7:55 PM
P
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
B
been thinking the same thing ...
Apr 21, 2020, 8:06 PM
B
99% of the time, i'm probably also the document editor, and i'll know the video already
Apr 21, 2020, 8:06 PM
B
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.