Concatenate multiple fields for document title in Sanity Studio list view
Yes, you can absolutely customize the document title in the Studio list view by using the preview configuration in your schema! This is done using the select and prepare functions.
Here's how you'd achieve your specific use case of concatenating the license plate, model, and manufacturer:
{
name: 'vehicle', // or whatever your document type is called
type: 'document',
fields: [
{ title: "License Plate", name: "licensePlate", type: "string" },
{ title: "Model", name: "model", type: "string" },
{
title: "Manufacturer",
name: "manufacturer",
type: "array",
of: [
{
type: 'reference',
to: [{type: "manufacturer"}]
}
]
}
],
preview: {
select: {
licensePlate: 'licensePlate',
model: 'model',
// Use dot notation to dereference the first manufacturer reference
manufacturerName: 'manufacturer.0.name'
},
prepare({licensePlate, model, manufacturerName}) {
return {
title: `${licensePlate} - ${manufacturerName} ${model}`
}
}
}
}The key points here:
select: This specifies which fields to pull from your document. For the manufacturer reference, I'm usingmanufacturer.0.namewhich accesses the first item in the array (0) and then dereferences it to get thenamefield using the->operator (represented by dot notation in the select).prepare: This function receives the selected values and returns an object with the formattedtitlethat will appear in the list view.
If your manufacturer reference might not always be set, you can add a fallback:
prepare({licensePlate, model, manufacturerName}) {
return {
title: `${licensePlate || 'No Plate'} - ${manufacturerName || 'Unknown'} ${model || 'Unknown Model'}`
}
}You can learn more about preview configuration and dereferencing references in the official Sanity documentation on previews and list views.
Show original thread5 replies
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.