Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Setting the name of a collection

default discord avatar
taun21602 years ago
10

Currently the name defaults to the slug Blogcategories, I'd like to set the name Blog Categories?



import { CollectionConfig } from 'payload/types';

const BlogCategories: CollectionConfig = {
  slug: 'blogcategories',
  admin: {
    useAsTitle: 'name',
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
    },
  ],
  timestamps: false,
};

export default BlogCategories;
  • default discord avatar
    notchr2 years ago

    Good afternoon

    @479030528084017165

    !



    Check out the "labels" property on collections



    https://payloadcms.com/docs/configuration/collections
  • default discord avatar
    taun21602 years ago

    Oh yes, forgot about labels.. Thanks Chris.

  • default discord avatar
    notchr2 years ago

    No prob 😄

  • default discord avatar
    taun21602 years ago

    How is it written? Clearly not like this:


     import { CollectionConfig } from 'payload/types';
    
    const BlogCategories: CollectionConfig = {
      slug: 'blog_categories',
      label: 'Blog Categories',
      admin: {
        useAsTitle: 'name',
      },
      access: {
        read: () => true,
      },
      fields: [
        {
          name: 'name',
          type: 'text',
        },
      ],
      
      timestamps: false,
    };
    
    export default BlogCategories;


    In the docs i found an example of a field label in use, but not for the name of the collection



     fields: [
        {
          name: 'title',
          label: 'Page Title',
          type: 'text',
          required: true,
          localized: true,
        },
  • default discord avatar
    tinouti2 years ago

    Pretty sure the automatic labels also respect camel case. So setting the slug to

    blogCategories

    should also work.

  • default discord avatar
    taun21602 years ago

    By naming it do you mean labeling it? Or sluggin it?

  • default discord avatar
    tinouti2 years ago

    Haha sorry just updated my message 😂

  • default discord avatar
    taun21602 years ago

    Haha, cool, thanks. I assume camelcase is also GraphQL friendly?



    I received a graphql regarding the name, not sure what that was about.



    Do you know how I can define the label, instead of using the slug?

  • discord user avatar
    tylandavis
    2 years ago

    To change the label of the collection, use

    labels

    on your collection config.


    labels: {
      singular: 'Blog Category',
      plural: 'Blog Categories'
    }
  • default discord avatar
    tinouti2 years ago

    I was gonna link to the docs, but looks like we don't use the

    labels

    property in the examples (

    https://payloadcms.com/docs/configuration/collections

    ). Probably a good PR opportunity there. 😄

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.