Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to display the _id field in Sanity Studio

6 replies
Last updated: Mar 4, 2023
Hey everybody, how can i get _id of item and show it in GUI.This is shema of item:

export default {
  title: 'Objednávky',
  name: 'order',
  type: 'document',
  icon: MdFoodBank,
  fields: [   
    {
      name: 'id',
      title: 'Objednávka:',
      type: 'string',
      readOnly: true,     
    },
    {
      name: 'note',
      title: 'Poznámka',
      type: 'string',
    },    
  ],
Thank you
Mar 3, 2023, 12:51 PM
You mean in Sanity Studio? All variables that are prefixed with underscore (
_
) seems to be treated as private variables so they don’t normally show up.
Mar 3, 2023, 1:08 PM
If you really like, I can think of creating a custom component for such purposes
Mar 3, 2023, 1:10 PM
Thx
user G
, yes Studio. Component is very good for input, but i just wanna only show up "_id", not edit (my field is readyOnly).
Mar 3, 2023, 1:42 PM
If you try to add a field with the name
_id
to your schema—even if read-only—you’ll get an error and the studio won’t build. Using
name: 'id'
is fine, but by default the studio treats that entirely separate from
_id
. As Dorell mentioned, you’ll want to use a custom component and source the data from your
_id
.
Mar 3, 2023, 2:50 PM
Oh, ok, thank you
user A
and
user G
Mar 3, 2023, 4:01 PM
you’re welcome
user M
😊
Mar 4, 2023, 1:15 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?