Nested folders in Sanity Next.js

6 replies
Last updated: Jan 27, 2026
Is it possible to have nested folders in sanity nextjs? please help
AI Update

I think you might be asking about organizing your content in a nested folder-like structure in Sanity Studio when working with a Next.js project. The good news is yes, this is absolutely possible using the Structure Builder API!

The Structure Builder lets you create infinitely-nestable categories that work just like folders. Instead of seeing a flat list of all your document types, you can organize them hierarchically however makes sense for your content.

Here's a simple example of creating nested "folders" in your Studio:

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

export const structure: StructureResolver = (S) =>
  S.list()
    .title('Content')
    .items([
      // Create a "folder" for Blog content
      S.listItem()
        .title('Blog')
        .child(
          S.list()
            .title('Blog Content')
            .items([
              S.documentTypeListItem('post').title('Posts'),
              S.documentTypeListItem('author').title('Authors'),
              S.documentTypeListItem('category').title('Categories'),
            ])
        ),
      
      // Create another "folder" for Products
      S.listItem()
        .title('Products')
        .child(
          S.list()
            .title('Product Content')
            .items([
              S.documentTypeListItem('product').title('Products'),
              S.documentTypeListItem('collection').title('Collections'),
            ])
        ),
      
      // Single items at root level
      S.documentTypeListItem('settings').title('Settings'),
    ])

Then wire it up in your sanity.config.ts:

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {structure} from './structure'

export default defineConfig({
  // ...other config
  plugins: [
    structureTool({structure}),
    // ...other plugins
  ],
})

You can nest these as deeply as you want, and you can even create filtered lists within folders (like "Published Posts" vs "Draft Posts"). You can also organize media assets in folders based on properties like size or type.

This folder structure is purely organizational in the Studio - it doesn't affect how you query or structure your Next.js app. Your Next.js routing and file structure are completely independent from how you organize content in the Studio.

Show original thread
6 replies

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?