Set Up Knowledge Base Collection in Payload CMS

First, you need to create a collection in Payload CMS for the knowledge base articles.

Create the Knowledge Base Collection in Payload CMS

  1. Go to your Payload CMS project folder.
  2. In the collections folder, create a new file for the knowledge base, such as KnowledgeBase.js (or .ts for TypeScript).
  3. Define the structure of your knowledge base collection. Example:
// collections/KnowledgeBase.js

module.exports = {
  slug: 'knowledge-base', // this will be the endpoint for the knowledge base articles
  labels: {
    singular: 'Knowledge Base Article',
    plural: 'Knowledge Base Articles',
  },
  fields: [
    {
      name: 'title',
      label: 'Title',
      type: 'text',
      required: true,
    },
    {
      name: 'content',
      label: 'Content',
      type: 'richText',
      required: true,
    },
    {
      name: 'example',
      label: 'Example',
      type: 'textarea',
      required: true,
    },
    {
      name: 'category',
      label: 'Category',
      type: 'select',
      options: [
        { label: 'General', value: 'general' },
        { label: 'Technical', value: 'technical' },
        { label: 'How-to', value: 'how-to' },
      ],
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'date',
      defaultValue: () => new Date().toISOString(),
    },
  ],
};

Register the Collection

  1. Open the payload.config.js file (or ts if you’re using TypeScript).
  2. Register the new collection:
js

Copy code
// payload.config.js
const KnowledgeBase = require('./collections/KnowledgeBase');

module.exports = {
  collections: [KnowledgeBase],
  // other config...
};

Leave a comment

Your email address will not be published. Required fields are marked *