Hey,
I've added preview function to 8 different collections, but for some reason it only appears on a few of them. Are there any configurations that could prevent such a button from being shown? Not really sure if it is a bug, or me missing something crucial
Example non-working code (same preview function is used in the working code as well):
export const Plans: CollectionConfig = {
slug: 'plans',
admin: {
useAsTitle: 'title',
preview: (doc, { locale }) => {
if (doc?.slug) {
return `https://bigbird.com/preview/posts/${doc.slug}?locale=${locale}`;
}
return null;
},
},
},
access: DEFAULT_ACCESS_CONTROL,
fields: [
{
name: 'title',
label: 'Title',
type: 'text',
localized: true,
},
{
name: 'id',
label: 'Custom ID',
type: 'text',
},
buttons,
],
timestamps: false,
}
In your above code, if (doc?.slug)
makes the preview button only show if there's a slug.
You can write another condition or remove the condition and just return the preview URL.
As an example:
export const Plans: CollectionConfig = {
slug: 'plans',
admin: {
useAsTitle: 'title',
preview: (doc, { locale }) => {
// Always return the same preview URL for the plans collection in each locale
return `https://bigbird.com/preview/plans?locale=${locale}`;
},
},
access: DEFAULT_ACCESS_CONTROL,
fields: [
{
name: 'title',
label: 'Title',
type: 'text',
localized: true,
},
{
name: 'id',
label: 'Custom ID',
type: 'text',
},
buttons,
],
timestamps: false,
}
Ahh, noticed it will not appear, unless you have a slug
field added. Could we adjust it? I want to have a preview button for collections which are all grouped on one page, so I do not require slug in some instances
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.