You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Global configs are in many ways similar to [Collections](/docs/configuration/collections). The big difference is that Collections will potentially contain *many* documents, while a Global is a "one-off". Globals are perfect for things like header nav, site-wide banner alerts, app-wide localized strings, and other "global" data that your site or app might rely on.
9
+
Global configs are in many ways similar to [Collections](/docs/configuration/collections). The big difference is that Collections will potentially contain _many_ documents, while a Global is a "one-off". Globals are perfect for things like header nav, site-wide banner alerts, app-wide localized strings, and other "global" data that your site or app might rely on.
10
10
11
11
As with Collection configs, it's often best practice to write your Globals in separate files and then import them into the main Payload config.
|**`slug`*** | Unique, URL-friendly string that will act as an identifier for this Global. |
18
-
|**`fields`*** | Array of field types that will determine the structure and functionality of the data stored within this Global. [Click here](/docs/fields/overview) for a full list of field types as well as how to configure them. |
|**`slug`**\*| Unique, URL-friendly string that will act as an identifier for this Global. |
18
+
|**`fields`**\*| Array of field types that will determine the structure and functionality of the data stored within this Global. [Click here](/docs/fields/overview) for a full list of field types as well as how to configure them. |
19
19
|**`label`**| Text for the name in the Admin panel or an object with keys for each language. Auto-generated from slug if not defined. |
20
20
|**`description`**| Text or React component to display below the Global header to give editors more information. |
21
21
|**`admin`**| Admin-specific configuration. See below for [more detail](/docs/configuration/globals#admin-options). |
@@ -24,33 +24,33 @@ As with Collection configs, it's often best practice to write your Globals in se
24
24
|**`versions`**| Set to true to enable default options, or configure with object properties. [More](/docs/versions/overview#globals-config)|
25
25
|**`endpoints`**| Add custom routes to the REST API. [More](/docs/rest-api/overview#custom-endpoints)|
26
26
|**`graphQL.name`**| Text used in schema generation. Auto-generated from slug if not defined. |
27
-
|**`typescript`**| An object with property `interface` as the text used in schema generation. Auto-generated from slug if not defined. |
27
+
|**`typescript`**| An object with property `interface` as the text used in schema generation. Auto-generated from slug if not defined. |
28
28
29
-
*\* An asterisk denotes that a property is required.*
29
+
_\* An asterisk denotes that a property is required._
30
30
31
31
#### Simple Global example
32
32
33
33
```ts
34
-
import { GlobalConfig } from'payload/types';
34
+
import { GlobalConfig } from"payload/types";
35
35
36
36
const Nav:GlobalConfig= {
37
-
slug: 'nav',
38
-
fields: [
39
-
{
40
-
name: 'items',
41
-
type: 'array',
42
-
required: true,
43
-
maxRows: 8,
44
-
fields: [
45
-
{
46
-
name: 'page',
47
-
type: 'relationship',
48
-
relationTo: 'pages', // "pages" is the slug of an existing collection
49
-
required: true,
50
-
}
51
-
]
52
-
},
53
-
]
37
+
slug: "nav",
38
+
fields: [
39
+
{
40
+
name: "items",
41
+
type: "array",
42
+
required: true,
43
+
maxRows: 8,
44
+
fields: [
45
+
{
46
+
name: "page",
47
+
type: "relationship",
48
+
relationTo: "pages", // "pages" is the slug of an existing collection
49
+
required: true,
50
+
},
51
+
],
52
+
},
53
+
],
54
54
};
55
55
56
56
exportdefaultNav;
@@ -64,9 +64,47 @@ You can find an [example Global config](https://github.com/payloadcms/public-dem
64
64
65
65
You can customize the way that the Admin panel behaves on a Global-by-Global basis by defining the `admin` property on a Global's config.
66
66
67
-
| Option | Description |
68
-
| ---------------------------- | -------------|
69
-
|`components`| Swap in your own React components to be used within this Global. [More](/docs/admin/components#globals)|
|`components`| Swap in your own React components to be used within this Global. [More](/docs/admin/components#globals)|
70
+
|`preview`| Function to generate a preview URL within the Admin panel for this global that can point to your app. [More](#preview). |
71
+
72
+
### Preview
73
+
74
+
Global `admin` options can accept a `preview` function that will be used to generate a link pointing to the frontend of your app to preview data.
75
+
76
+
If the function is specified, a Preview button will automatically appear in the corresponding global's Edit view. Clicking the Preview button will link to the URL that is generated by the function.
77
+
78
+
**The preview function accepts two arguments:**
79
+
80
+
1. The document being edited
81
+
1. An `options` object, containing `locale` and `token` properties. The `token` is the currently logged-in user's JWT.
0 commit comments