Getting started
Example repository: See the example repository with Sanity schemas, block registry, and UI components already wired up. Clone it to explore a full setup or use it as reference while you adapt the steps below to your project.
You can also import the data exported from the example repository to your project. Check the README.md for more details.
Sanity is a powerful CMS, and each project can have its own specifics (folder structure, conventions, plugins, etc.). This documentation shows the most minimal approach — only what’s needed to use the blocks. You should adapt the examples to your setup, rules, and context.
Sanity Typegen: I've used Sanity
TypeGen to
generate TypeScript types from the schema. The registry and components import
types from the generated file (e.g. Blocks, Home in
sanity.types.ts). Configure and run typegen in your project per the
official
documentation.
Shared objects (optional)
Blocks that use CTA, links, etc. reuse shared objects. Example: the cta object. See Sanity › Shared for the list.
You need to export and include these types in your schema according to your project’s context (e.g. an objects index that re-exports cta and others).
Define a block (e.g. Grid Two Columns)
Define the blocks array (blocks.ts)
This is how I use blocks on a page: an array per category (e.g. content) referenced on the document type. When you add blocks or categories, update this file. The values in of refer to the schema type — if the type doesn’t exist in the project, the Studio will break.
Define a page type (e.g. home)
A document type like home uses the blocks array so editors can add blocks in the Studio. The field type: 'blocks' references the blocks schema defined in blocks.ts.
Block registry (UI)
When adding a new block, register it here. Import types from the generated file (e.g. Blocks from sanity.types.ts).