Setting the name of a collection

default discord avatar
taun2160
3 months ago
14

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
    notchr
    3 months ago

    Good afternoon @taun2160 !



    Check out the "labels" property on collections



    https://payloadcms.com/docs/configuration/collections
  • default discord avatar
    taun2160
    3 months ago

    Oh yes, forgot about labels.. Thanks Chris.

  • default discord avatar
    notchr
    3 months ago

    No prob 😄

  • default discord avatar
    taun2160
    3 months 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
    tinouti
    3 months ago

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

    blogCategories

    should also work.

  • default discord avatar
    taun2160
    3 months ago

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

  • default discord avatar
    tinouti
    3 months ago

    Haha sorry just updated my message 😂

  • default discord avatar
    taun2160
    3 months 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
    Payload Team
    3 months ago

    To change the label of the collection, use

    labels

    on your collection config.


    labels: {
      singular: 'Blog Category',
      plural: 'Blog Categories'
    }
  • default discord avatar
    tinouti
    3 months 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. 😄

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.