Replies: 5 comments 5 replies
-
I think you came to your own conclusions correctly on your own.
There isn't really a better way. Anything I think to extend in Payload's core to accomodate referrences to globals or something, it is still isn't a better solution than moving to a Pages collection. If you're expecting some magic undocumented tricks, I have bad news for you. Globals are great for variables in your projects like headers and footers, social media links, and 3rd party vendor variables that you want to expose to editors. |
Beta Was this translation helpful? Give feedback.
-
I guess that's fair enough. It is a bit frustrating that you can only have "a single global dataset" and "a collection of non-global datasets" without "a single non-global dataset". I think it would be great in future to maybe have Collections to be optionally single-instance. Maybe a max Collection limit? |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens I've started down the path of the solution suggested above, with one Pages collection with all of its fields conditional on its type - but it comes with definite drawbacks that feel insurmountable, unless I'm misunderstanding something (I'm only a couple weeks into using Payload at this point). My Pages collection config looks like this currently: fields: [
{
type: "text",
name: "title",
required: true,
},
{
name: "pageType",
type: "select",
required: true,
admin: {
position: "sidebar",
},
options: [
{ label: "Home", value: "home" },
{ label: "About", value: "about" },
{ label: "Contact", value: "contact" },
],
},
slugField(),
pathField(),
...HomeFields,
...AboutFields,
...ContactFields,
], Each imported array contains a labelled (not named) tabs field which is conditional on the value of
Given the issues above, it feels like there is still room for a different, once-off, non-global document "Single" type that lives somewhere between a Collection and a Global. |
Beta Was this translation helpful? Give feedback.
-
The problem would be that you dont have option to make relation to Globals... |
Beta Was this translation helpful? Give feedback.
-
I was able to work around this limitation by creating a conditional select field. When you select a import type { Field } from 'payload'
export const LinkField: Field = {
name: 'link',
type: 'group',
fields: [
{
name: 'type',
type: 'select',
required: true,
options: [
{
label: 'External Link',
value: 'external',
},
{
label: 'Homepage',
value: 'homepage',
},
{
label: 'Page',
value: 'page',
},
{
label: 'Blog',
value: 'blog',
},
{
label: 'Blog Post',
value: 'post',
},
],
},
{
name: 'url',
type: 'text',
required: true,
admin: {
condition: (_, siblingData) => siblingData?.type === 'external',
},
},
{
name: 'newWindow',
type: 'checkbox',
label: 'Open in new window',
admin: {
condition: (_, siblingData) => siblingData?.type === 'external',
},
},
{
name: 'pageReference',
type: 'relationship',
required: true,
relationTo: 'pages',
admin: {
condition: (_, siblingData) => siblingData?.type === 'page',
},
},
{
name: 'postReference',
type: 'relationship',
required: true,
relationTo: 'posts',
admin: {
condition: (_, siblingData) => siblingData?.type === 'post',
},
},
],
} |
Beta Was this translation helpful? Give feedback.
-
TL:DR;
I have structured my site so that one-off pages (eg. Homepage) are Globals, which introduces certain limitations (specifically being unable to reference Globals within Relationship fields). How do people generally structure these types of one-off and distinct pages within their projects?
I'm in the process of migrating our agency website away from another CMS - so far Payload has been fantastic, but I'm having some troubles understanding the intended (or otherwise optimal) architecture for structuring content within Payload. I can't tell if this is a missing feature, an idealogical schism, or just a mental model adjustment.
We deal primarily with highly-custom, highly-art-directed, bespoke websites and apps, we generally have a need for one-off page types. Homepage, Contact, About, etc. might all have vastly different needs, layouts and business requirements, to where a modular block-based approach to building one-off layouts does not make a great deal of sense. These are often pages where layout is largely static due to the high level of art-direction of each page, and fields are not often shared between them.
I've currently got my project structured so that the static art-directed pages are Globals, and other content types are Collections. This fits the bill nicely for defining the content models, but given the intrinsic differences between Globals and Collections, this structure has begun to pose some insurmountable obstacles.
My project structure looks like this:
Our Home, About, and Contact pages are each navigable pages - but being Globals, are omitted from Relationship fields (especially frustrating because this makes the custom Link field only allow certain internal links). I understand that there are also certain API differences between Globals and Collections as well, though I've not encountered those yet.
Looking at other projects, there seems to be a general pattern of creating a Pages collection whose content is largely driven by block-based layout building and hero "types". While I could restructure things to be this way - it would essentially mean that the Pages collection would have to contain a
type
field which basically every other field is conditional on. To re-iterate, the content model between these pages is generally not shared and not modular, and their layout is fairly static and bespoke.Am I going about this wrong? Are there other solutions I've just not encountered yet? Requiring a Pages Collection for one-off page content feels like an unnecessary hurdle that I would like to avoid entirely if I can help it.
This quote from the docs would support the use case for once-off navigable pages, though this seems to not be the intention.
Beta Was this translation helpful? Give feedback.
All reactions