Skip to content

templates Examples

The templates property allows you to define default values for new documents created from a specific list item. These are automatically mapped to Sanity Initial Value Templates.

Basic Usage

In this example, when a user creates a new "Post" from this list item, the status field will default to draft and publishedAt will be set to the current date.

ts
{
  schemaType: 'post',
  templates: {
    status: 'draft',
    publishedAt: new Date().toISOString(),
  },
}

Multiple Templates for Same Type

You can define multiple list items for the same schemaType with different initial values. The plugin will automatically generate unique template IDs for each.

ts
const listItems = defineListItems([
  {
    title: 'Featured Posts',
    schemaType: 'post',
    templates: {
      isFeatured: true,
      category: 'featured',
    },
  },
  {
    title: 'News Posts',
    schemaType: 'post',
    templates: {
      category: 'news',
    },
  },
]);

Registration

The structure utility handles template registration automatically, keeping your desk items and initial values in sync. For advanced use cases and manual merging, see the Configuration Guide.

Released under the MIT License.