id
- Type:
string | ((params: CallbackParams & { values: ListItemIdValues }) => string) - Optional: Yes
The id property uniquely identifies the list item in the Sanity desk menu path. If not provided, it is automatically generated using the unique item index and the slugified title.
Standard Usage
ts
{
id: 'custom-author-id',
title: 'Authors',
schemaType: 'author',
}ts
helpers.listing('author', {
id: 'custom-author-id',
title: 'Authors',
});Dynamic ID (Callback)
You can dynamically construct or customize the id using a callback. The callback receives standard desk context (workspace, currentUser, context) plus a values object containing auto-generated default values:
Callback values Object
| Property | Type | Description |
|---|---|---|
uniqueId | string | The base index-based ID generated by the plugin (e.g. 1.2.3). |
sanitizedPaths | string[] | An array of words from the title, sanitized and ready for URL use. |
id | string | The default ID string generated by the plugin (combining uniqueId and sanitized paths). |
slugify | (str: string) => string | The internal sanitize/slugify utility function. |
Example
ts
import { constants } from 'sanity-plugin-structure-tool';
{
title: 'My Custom Category',
schemaType: 'category',
// Dynamically prefix or suffix the ID based on active workspace
id: ({ workspace, values }) => {
return [workspace, values.uniqueId, 'category'].join(constants.URL_PATH_SEPARATOR);
},
}ts
import { constants } from 'sanity-plugin-structure-tool';
helpers.listing('category', {
title: 'My Custom Category',
id: ({ workspace, values }) => {
return [workspace, values.uniqueId, 'category'].join(constants.URL_PATH_SEPARATOR);
},
});For more details on the path separator constant, see the URL_PATH_SEPARATOR documentation.
