Trouble with generating slug field in Sanity Studio
options.sourcevalue (link ) so it knows where to derive the slug from.
import {defineField, defineType} from 'sanity'export default defineType({ title: "Event", // title of the doc, display name for the Uiname: "event", // when performing queries and hitting API'stype: "object",
fields: [
// always an array of objects
defineField({ title: "Event Name",
name: "eventName",
type: "string",
}),
defineField({ name: "slug",
title: "Slug",
type: "slug",
options: { source: "eventName",
maxLength: 96,
},
}),
defineField({ name: 'ticketType',
title: 'Ticket Type',
type: 'string',
options: { list: [
{ title: 'Ticketed', value: 'tix' }, { title: 'Guest List', value: 'gl' }, { title: 'Discounted', value: 'dic' }, { title: 'Soldout', value: 'so' }, ],
},
}),
defineField({ title: "Date",
name: "eventDate",
type: "date",
}),
defineField({ title: 'Event URL',
name: 'eventUrl',
type: 'url'
}),
defineField({ title: "Venue Name",
name: "venueName",
type: "string",
}),
defineField({ title: "Artists Performing",
name: "artists",
type: "string",
}),
defineField({ title: "Flyer",
name: "flyer",
type: "image",
options: { hotspot: true,
}
}),
],
}
);
3.2.4. The latest version is
3.2.6.
eventNameon the document and not finding that field since it’s nested under your
event. I was able to get it to work by changing the source to the following:
source: (doc, { parent }) => parent.eventName,The [Object] below represent an event document/category
[
{ _createdAt: '2023-01-27T10:50:55Z',
_id: '26d56839-2903-4353-b039-1365f2100f81',_rev: '0mmgc4CDWeXHLRG7XO0GKF',
_type: 'events',
_updatedAt: '2023-02-04T05:18:56Z',
city: 'sc',
events: [ [Object] ]
},
{ _createdAt: '2023-01-27T10:58:46Z',
_id: 'f3ec5bbf-e124-4503-9b58-917dee7e6569',_rev: '0mmgc4CDWeXHLRG7X7zkHP',
_type: 'events',
_updatedAt: '2023-02-03T03:35:29Z',
city: 'sf',
events: [ [Object], [Object] ]
}
]
*[_type=='events'] { events[] { slug
}
}
I have attempted, but unfortunately it did not work
*[_type=='event' && event.slug.current == "perro-paradise"]Was this answer helpful?
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.