If I'm not getting the 'Preview' option on sanity studio that probably means that I haven't setup previewmode correctly on my project right?

3 replies
Last updated: Oct 19, 2020
Hey, just a quick question. If I'm not getting the 'Preview' option on sanity studio that probably means that I haven't setup previewmode correctly on my project right?
AI Update

Yes, you're on the right track! If you're not seeing a 'Preview' option in Sanity Studio, it likely means the Presentation Tool hasn't been configured yet.

The Presentation Tool is a plugin that needs to be explicitly added to your sanity.config.ts file. Here's what you need to do:

1. Make sure you're running Studio v3.40.0 or later:

npm install sanity@latest

2. Add the Presentation Tool plugin to your config:

import { presentationTool } from 'sanity/presentation'

export default defineConfig({
  // ... other config settings
  plugins: [
    presentationTool({
      previewUrl: {
        previewMode: {
          enable: '/api/draft-mode/enable',
        },
      },
    }),
  ],
})

3. Set up your frontend to handle preview mode: You'll also need to implement Visual Editing support in your frontend application. This involves:

  • Creating an API route that enables draft mode (like the /api/draft-mode/enable endpoint referenced above)
  • Configuring your app to fetch and display draft content
  • Setting up proper authentication tokens

The specific implementation depends on your framework. Sanity has guides for Next.js, Nuxt.js, SvelteKit, and React Router/Remix.

Once configured, you'll see the Presentation Tool option appear in your Studio's top toolbar, giving you that live preview with click-to-edit functionality!

Probably, you need to create a resolver function that takes a document and returns the URL, then register that function in sanity.json

https://www.sanity.io/docs/preview-content-on-site
Thanks πŸ˜›. I've done that but I'm most likely doing something wrong. Will try to get it working πŸ˜›
oof got it working. It was a mix of having a wrong projectid and a bit of difficulty of integrating the preview mode with Next.js

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?