I've noticed I can add a preview to an image type but it only pulls data from the settings field name in the fields[] within it.
Good news - yes, you can reference the parent image asset in your preview! The issue is that when you're working with an image type, the actual asset reference is stored in a nested asset property, not directly on image.
Based on the preview configuration documentation, you need to use dot notation to access the asset. Try this:
preview: {
select: {
size: 'settings.size',
artist: 'settings.artistCredit.title',
caseStudy: 'settings.caseStudy.content.title',
media: 'asset' // Reference the asset directly
},
prepare({ size, artist, caseStudy, media }) {
return {
title: caseStudy || artist || 'Image',
subtitle: size,
media: media
}
},
}The key is using 'asset' instead of 'image' in your select. When you're defining a preview within an image type definition, you're already in the context of that image object, so you can reference asset directly.
If you need to access other properties of the image object (like hotspot or crop data), you can also select those:
select: {
size: 'settings.size',
artist: 'settings.artistCredit.title',
media: 'asset',
hotspot: 'hotspot',
crop: 'crop'
}The preview system lets you access nested fields using dot notation, and you can even access items in arrays using numeric indices (like 'images.0.asset' for the first image in an array). This works for both regular fields and referenced documents.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.