Issue with filtering out a document by ID in Sanity Studio using desk structure.
Looking at your code, I can see the issue. When you want to create a filtered list of documents in Structure Builder, you should use S.documentList() or S.documentTypeList() instead of S.document(), since S.document() is for rendering a single specific document, not a list.
Here's how to fix your code:
S.listItem()
.title("Audit template")
.icon(FaBible)
.child(
S.document()
.schemaType("revisionTemplate")
.documentId("sourceDocument")
),
S.listItem()
.title("Audits")
.child(
S.documentList()
.title("Audits")
.filter('_type == "revisionTemplate" && _id != "sourceDocument"')
.schemaType("revisionTemplate")
),The key changes:
- Use
S.documentList()instead ofS.document()- this creates a list view that can display multiple documents - Use the
.filter()method with a GROQ query - the filter takes a GROQ string, not a function. In your case:'_type == "revisionTemplate" && _id != "sourceDocument"' - Add a
.title()to give your list a proper heading
This setup will give you two separate list items in your Structure:
- "Audit template" - shows only the single document with ID "sourceDocument"
- "Audits" - shows all other
revisionTemplatedocuments except the one with ID "sourceDocument"
The Structure Builder documentation explains that S.documentList() is specifically designed for creating filtered lists of documents, and it accepts GROQ filter strings to query which documents to display. You can also check out the getting started guide for more examples of filtering and organizing documents.
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.