Schemas and snippets
Handle Certain Values To Be True
If you want to pass a parameter to a query that might not always be defined
Go to Handle Certain Values To Be TrueDelete documents using sanity cli
This bash script can be used to delete documents using sanity cli.
Go to Delete documents using sanity cliValidation of children in objects
How to validate nested fields from the document or object level
Go to Validation of children in objectsGet parents parent in reference filter
Get parents parent in reference filter
Go to Get parents parent in reference filter'Hacking' custom Document Actions 😇
A little 'hack' when you work on custom Document actions
Go to 'Hacking' custom Document Actions 😇Is your Microcopy unique?
A custom validation to check if your Microcopy documents have unique keys and values for a specific namespace.
Go to Is your Microcopy unique?Select draft OR published document
Setting up a live preview and want to fetch a document's draft, with a fallback for the published document when there are no drafts? Check this out.
Go to Select draft OR published documentOne or the other validation
This validation can be used if you have two fields and you require one or the other to be filled
Go to One or the other validationGet current, previous and next post, filtered by tags
This snippet can be used to fetch current, previous and next articles based on publication date and related tags.
Go to Get current, previous and next post, filtered by tagsValidation of url input to allow certain URI schemes
Validation of url input to allow certain URI schemes (mailto, tel and more included)
Go to Validation of url input to allow certain URI schemesAsynchronous List Options Component
Populate your list options in a string schema using an external API
Go to Asynchronous List Options ComponentFilter Array Options Based on the Current User Role
Use the renderDefault function to easily control your available array options.
Go to Filter Array Options Based on the Current User RoleUsing GROQ to create an excerpt for a Sanity block
This is a quick tip on how to truncate a Sanity block field to create an excerpt using GROQ.
Go to Using GROQ to create an excerpt for a Sanity blockUse GROQ to order by last name in where name is stored as full name
Order by last name
Go to Use GROQ to order by last name in where name is stored as full nameCustom validation on array length
Simple custom validation that force array length according to another field.
Go to Custom validation on array lengthSchema validation rules to enforce image size or file type
Uses @sanity/asset-utils to validate an uploaded image by its ID
Go to Schema validation rules to enforce image size or file typeSchema validation rules to enforce maximum file size
Prevent references to large files to reduce the chances of high bandwidth usage
Go to Schema validation rules to enforce maximum file size