Create Global
Global is similiar to collection, but it’s only one row of data. We can’t add more row of global data. But we can add more than one globals.
Global is usefull for setting UI Items such as Logo, Footer, Section or other configuration for the website.
How to create a global
-
Create a new file named
General.tsinside theglobalsfolder.Directorypublic/
- …
- src
Directoryapp
Directory(landing)/
- …
Directorycollections/
- …
Directoryglobals
- General.ts
- package.json
- next.config.ts
The global configuration is similiar to collection configuration. Here an example of the Global config :
src/globals/General.ts import { GlobalConfig } from "payload";export const General: GlobalConfig = {slug: "general",fields: [{name: "logo",type: "upload",required: true,relationTo: "media",},{name: "brandName",label: "Brand Name",type: "text",required: true,},{name: "entityName",label: "Entity Name",type: "text",required: true,},{name: "businessEmail",label: "Email Bisnis",type: "email",},{name: "businessPhone",type: "text",label: "Nomor Telepon Bisnis",},{name: "businessAddress",type: "textarea",label: "Alamat Bisnis",},{name: "googleMapsPlaceId",type: "text",label: "Google Maps Place ID",}],access: {read: () => true,}}; -
Add the General global to the
globalsarray in thepayload.config.tsfile.src/payload.config.ts import { General } from './globals/General'export default buildConfig({// ...otherConfig,globals: [General],}) -
You’re set! Now check out the dashboard and you’ll see the new General globals.