✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Frequently asked questions

By Knut Melvær

Simple content type for a question and answer pattern

faq.js

// faq.js
export default {
  name: 'faq',
  type: 'object',
  title: 'Frequently asked question',
  fields: [
    {
      name: 'question',
      type: 'string',
      title: 'Question'
    },
    {
      name: 'answer',
      type: 'text',
      title: 'Answer',
    }
  ]
}

Help article

// helpArticle.js
export default {
  name: 'helpArticle',
  type: 'document',
  title: 'Help article',
  fields: [
    {
      name: 'title',
      type: 'string',
      title: 'Title'
    },
    {
      name: 'faqs',
      type: 'array',
      title: 'Frequently Asked Questions',
      of: [
        {
          type: 'faq'
        }
      ]
    }
  ]
}

schema.js

// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator';

// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type';

// other imports
// ...
import faq from './faq'

export default createSchema({
  name: 'default',
  types: schemaTypes.concat([
    // ... other types,
    faq
  ])
})

If you import this schema into schemas.js, then you can use this pattern as type: 'faq' elsewhere.

Contributor

Other schemas by author