How to remove the "Create New Document" action from a specific part of the document list structure.

3 replies
Last updated: May 10, 2024
Anybody know how to remove the "Create New Document" action (the + icon) from a document list. I've got a structure like this: Programs > By Department > Departments > Programs. I'm not sure I want editors to being to create Departments or Programs from this particular part of the desk structure, but I do want them to be able to create new documents from the main "Create" new document button in the Studio and also if they're under the main Department and/or Programs list, but not from these filtered lists. I'm also not sure that content editors wouldn't want to be able to create new documents in this context, but I'm curious nonetheless. Thanks.
AI Update

You can control the "Create New Document" button (the + icon) on a per-pane basis in your Structure Builder configuration using initialValueTemplates([]). This is perfect for your use case where you want to disable document creation in certain filtered list views while keeping it available elsewhere.

Here's how to implement it in your nested structure:

// structure/index.ts
import type {StructureResolver} from 'sanity/structure'

export const structure: StructureResolver = (S) =>
  S.list()
    .id('root')
    .title('Content')
    .items([
      // Your nested structure
      S.listItem()
        .title('Programs')
        .child(
          S.list()
            .title('By Department')
            .items([
              S.listItem()
                .title('Departments')
                .child(
                  S.documentList()
                    .title('Departments')
                    .schemaType('department')
                    .filter('_type == "department"')
                    // Remove the + button from this list
                    .initialValueTemplates([])
                ),
              S.listItem()
                .title('Programs')
                .child(
                  S.documentList()
                    .title('Programs')
                    .schemaType('program')
                    .filter('_type == "program"')
                    // Remove the + button from this list too
                    .initialValueTemplates([])
                ),
            ])
        ),
      
      // Keep creation enabled in these main lists
      S.documentTypeListItem('department').title('All Departments'),
      S.documentTypeListItem('program').title('All Programs'),
    ])

The .initialValueTemplates([]) method removes all creation options from that specific document list pane. By passing an empty array, you're telling Studio "don't show any document creation templates for this list."

This approach gives you granular control - the main "Create" button in the global Studio menu will still work, and your "All Departments" and "All Programs" lists will still have the + icon, but your filtered nested views won't.

If you later decide you want some templates but not all, you can be more selective by filtering specific templates instead of passing an empty array. The Initial Value Templates documentation and this Structure Builder guide have more details on advanced customization options.

Maybe I'm using the wrong structure builder list item because I just noticed that the Programs list on the far left has chevron icons to the right indicating a sublist, whereas the departments list is lacking those chevron icons suggesting it opens a document, but surprise surprise it opens another list of programs. Hmm...
And in that case, I'd actually prefer the + icon remain on the filtered programs list so that they can create new programs that are automatically populated with the department they're currently under
In case anyone cares, I was able to modify the code from here to achieve what I was after: https://www.sanity.io/guides/parent-child-taxonomy#91b8b58d75d4?search=structure%20posts%20by%20category

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.

Was this answer helpful?