How to use documentTypeList without the create button in Sanity?

11 replies
Last updated: Sep 19, 2023
Hello everyone, it's User! I was wondering if there's a way to use a
documentTypeList
without having the create button action at the top of the pane. Unfortunately, using a static list doesn't work for us because it removes the search and ordering features that we need to keep in the pane. Your help would be greatly appreciated.
AI Update

Yes, absolutely! You can hide the create button on a documentTypeList while keeping the search and ordering features by using the .initialValueTemplates([]) method.

Based on your use case, here's how to modify your structure:

S.listItem()
  .title('Blog Posts by Category')
  .child(
    S.documentTypeList('blogCategory')
      .title('Blog Categories')
      .initialValueTemplates([])  // <-- This removes the create button
      .child((categoryId: string) =>
        S.documentList()
          .title('Blog Posts')
          .filter('_type == "blog" && references($categoryId)')
          .params({ categoryId })
      )
  )

The key is adding .initialValueTemplates([]) to your documentTypeList. By passing an empty array, you're telling Sanity not to show any document creation options for that specific list, which effectively hides the "+" button.

This approach is perfect because:

  • It only affects the specific documentTypeList where you add it
  • Search and ordering features remain fully functional
  • You don't need to create custom components
  • Other document lists in your structure keep their create buttons

If you want to learn more about how initial value templates work, check out the Initial Value Templates documentation. There's also a comprehensive Structure Builder API reference that covers all the available methods for the sanity/structure package.

Show original thread
11 replies
Not sure but this maybe works using templates filter in your config.
export default defineConfig({
  // ... other configs
  schema: [
    types: [
      // ... your types
    ],
    templates: (prev) => prev.filter((template) => !['product'].includes(template.id)),
  ]
})
Hey User! I really appreciate your response, but unfortunately, the snippet didn't work this time. I'm still seeing the create button at the top of the pane.
Oh no! and your document name is 'product'? I gave it a shot anyway πŸ™‚
Yes, the name is "product" πŸ™‚What version of Sanity are you currently in? I'm using the
3.11.1
Alright, I'm using
3.16.7
Ah! So let me check if your snippet works by updating the studio πŸ‘
Cool! I'm no Sanity expert. Just trying to learn. But it worked when I tried.
Sure, no problem. Thanks for sharing the code snippet and supporting.
user T
Hey there! I just wanted to let you know that I had initially placed the code snippet you shared with me in the wrong spot. But thanks to you, the issue is now solved! πŸ˜„By any chance, when you get a moment, could you please share the documentation you used to find that snippet? I'm really eager to learn more about it.
Hope you have a fantastic day!
Haha fantastic! Well it's kind a random. I'm using the Document Internationalization plugin for Sanity and in the bottom of the readme there is a link called "Remove default new document template" and while testing it out I got the result you were looking for.
https://github.com/sanity-io/document-internationalization/blob/210fd462eed177ff55[…]896154318a6756a/docs/06-remove-default-new-document-template.md
Perfect timing then! haha πŸ™‚Thanks again for your support.

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?