Skip to Content
Delmare Digital
Reference

Plugin options

Every option createPuckPlugin accepts, with types and defaults.

createPuckPlugin(options) from @delmaredigital/payload-puck/plugin takes these options. All are optional.

Prop

Type

Detail for each group of options is on its own page: access defaults, layouts, theme, editorStylesheets, pageTreeIntegration, rootPropsMapping and ai.

What the plugin registers

  • The puck-templates collection, always, unless one already exists.
  • The puck-ai-prompts and puck-ai-context collections, when ai.enabled and ai.promptsCollection / ai.contextCollection are set.
  • The pages collection (or Puck fields on your existing one), when autoGenerateCollection is true.
  • Endpoints under /api/puck/: :collection (GET, POST), :collection/:id (GET, PATCH, DELETE), :collection/:id/versions (GET) and :collection/:id/restore (POST); plus ai (POST), ai-prompts and ai-context (GET, POST, and PATCH, DELETE by :id) when AI is enabled.
  • The puckEditor admin view.

You can use the plugin more than once, for several page collections. Each call adds its collection to the shared endpoints.

admin

Prop

Type

previewUrl

payload.config.ts
// Static prefix
createPuckPlugin({
  previewUrl: '/preview',
})

// Prefix from page data
createPuckPlugin({
  previewUrl: (page) => `/${page.slug || ''}`,
})

// Organization-scoped pages (multi-tenant)
createPuckPlugin({
  previewUrl: (page) => {
    const orgSlug = page.organization?.slug || 'default'
    return (slug) => slug ? `/${orgSlug}/${slug}` : `/${orgSlug}`
  },
})

When previewUrl is a function, the page document is fetched with depth: 1, so relationship fields are populated.

The editor view is a server component, and functions can't be passed to the client. So the server calls your function with the page document; if the result is itself a function, it calls that with '' to get the base prefix, and sends the prefix to the client, which rebuilds the URL. A returned function must return just the prefix when called with an empty slug, as the multi-tenant example does.

Edit this page on GitHub

On this page