sittari-studio

templates

by sittari-studio
payload-plugins
Admin customization
v4
^4.0.0-0
MIT

Overview

Summary generated from the README

Creates one managed document per developer-defined template, which editors can change but not create, duplicate, delete or rename. A templateField helper adds a group to any collection, global, tab, array or block that stores local overrides and inherits empty values from the template on read. Includes a typed template getter and requires Payload 4.

Features

  • One managed document per template, created, relabeled and removed on Payload initialization
  • Access rules block creating or deleting template documents and changing their identity
  • templateField group stores only overrides and inherits empty values at read time
  • Admin placeholders show template values plus a link to edit the template
  • Context option switches Local API reads between raw and resolved values
  • Typed createTemplateGetter helper for fetching a template by name

Use cases

  • Define default hero or 404 page content that pages can selectively override
  • Give editors fixed, non-deletable content documents such as site-wide fallback text

From the author

Managed template documents for Payload CMS.

Installation

npm i @sittari/payload-templates

0

Stars

0

Forks

0

Open Issues

2 months ago

Last Updated

27

Weekly Downloads

v0.5.0

npm Version

91.7 KB

Unpacked Size

1

Dependencies

Repository stars

00 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260
Oct 17, 20260
Oct 16, 20260
Oct 15, 20260
Oct 14, 20260
Oct 13, 20260
Oct 12, 20260
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
Sep 12, 20260
Sep 11, 20260
Sep 10, 20260
Sep 9, 20260
Sep 8, 20260
Sep 7, 20260
Sep 6, 20260

Shared by 8 plugins in sittari-studio/payload-plugins.

npm weekly downloads

12−350 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202612
Dec 4, 202613
Dec 3, 202613
Dec 2, 202611
Dec 1, 202615
Nov 30, 202615
Nov 29, 202614
Nov 28, 202613
Nov 27, 202613
Nov 26, 202613
Nov 25, 20266
Nov 24, 20262
Nov 23, 20262
Nov 22, 20264
Nov 21, 20264
Nov 20, 202612
Nov 19, 202612
Nov 18, 202620
Nov 17, 202620
Nov 16, 202620
Nov 15, 202619
Nov 14, 202619
Nov 13, 202610
Nov 12, 202612
Nov 11, 20263
Nov 10, 202611
Nov 9, 202619
Nov 8, 202621
Nov 7, 202621
Nov 6, 202621
Nov 5, 202620
Nov 4, 202623
Nov 3, 202615
Nov 2, 20267
Nov 1, 20264
Oct 31, 20265
Oct 30, 20265
Oct 29, 20264
Oct 28, 20261
Oct 27, 20261
Oct 26, 20263
Oct 25, 20263
Oct 24, 20263
Oct 23, 20263
Oct 22, 20265
Oct 21, 202614
Oct 20, 202615
Oct 19, 202613
Oct 18, 202620
Oct 17, 202623
Oct 16, 202627
Oct 15, 202628
Oct 14, 202619
Oct 13, 202618
Oct 12, 202618
Oct 11, 202612
Oct 10, 202617
Oct 9, 202621
Oct 8, 202620
Oct 7, 202621
Oct 6, 202629
Oct 5, 202629
Oct 4, 202632
Oct 3, 202632
Oct 2, 202625
Oct 1, 202623
Sep 30, 202625
Sep 29, 202617
Sep 28, 202631
Sep 27, 202628
Sep 26, 202625
Sep 25, 202629
Sep 24, 202639
Sep 23, 202646
Sep 22, 202655
Sep 21, 202670
Sep 20, 2026199
Sep 19, 2026194
Sep 18, 2026189
Sep 17, 2026189
Sep 16, 2026186
Sep 15, 2026188
Sep 14, 2026163
Sep 13, 202639
Sep 12, 202640
Sep 11, 202654
Sep 10, 202655
Sep 9, 202673
Sep 8, 2026368
Sep 7, 2026364
Sep 6, 2026362

Each point is npm's rolling 7-day download count.

Health Score

62/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1294311885-templates.svg)](https://payloaddirectory.dev/plugins/1294311885-templates)
HTML
<a href="https://payloaddirectory.dev/plugins/1294311885-templates"><img src="https://payloaddirectory.dev/badge/1294311885-templates.svg" alt="Payload Directory"></a>
Updated Sep 11, 2026Created Jul 8, 2026Published Sep 11, 2026

README

@sittari/payload-templates

A Payload CMS plugin that creates one managed document for every developer-defined template. Users can edit template content, but cannot create, duplicate, delete, or change the identity of template documents.

Install

pnpm add @sittari/payload-templates

Usage

import { templateField, templatesPlugin } from '@sittari/payload-templates';
import { buildConfig } from 'payload';

export default buildConfig({
  collections: [
    {
      slug: 'pages',
      fields: [
        templateField({
          name: 'notFoundContent',
          template: '404',
        }),
      ],
    },
  ],
  plugins: [
    templatesPlugin({
      templates: [
        {
          name: '404',
          label: 'Page 404',
          fields: [
            { name: 'heading', type: 'text', required: true },
            { name: 'message', type: 'textarea' },
          ],
          initialData: {
            heading: 'Page not found',
          },
        },
      ],
    }),
  ],
});

The generated document stores editable fields under data_<name>—for example, data_404.heading. The title and templateType fields are managed by the plugin and hidden from the admin form.

Template-backed fields

templateField()

templateField(config: TemplateFieldConfig): GroupField

Creates a named Payload group whose fields and fallback values come from a template registered with templatesPlugin(). It can be used anywhere Payload accepts fields, including collections, globals, tabs, arrays, and blocks.

import { templateField } from '@sittari/payload-templates';
import type { CollectionConfig } from 'payload';

export const Pages: CollectionConfig = {
  slug: 'pages',
  fields: [
    templateField({
      name: 'hero',
      template: 'defaultHero',
      label: {
        en: 'Hero overrides',
        uk: 'Перевизначення Hero',
      },
      admin: {
        hideGutter: true,
      },
    }),
  ],
};
OptionTypeRequiredDescription
namestringYesField name used in the consuming document. Its stored overrides live at this property.
templatestringYesname of a template registered with templatesPlugin(). Unknown names throw during configuration.
labelGroupField['label']NoPayload group label. Static strings, localized label maps, and label functions are supported.
adminGroupField['admin']NoPayload Admin settings for the generated group. The plugin preserves these settings and installs its template field renderer.

The function initially returns a marked group definition. During plugin configuration, templatesPlugin() replaces its empty field list with an optionalized copy of the registered template fields and adds the fallback hook. Consequently, templateField() must be used in the same Payload config as an enabled templatesPlugin() call containing the referenced template.

The consuming document stores only local overrides:

// Managed template: data_defaultHero
{
  heading: 'Build something useful',
  summary: 'Default summary',
}

// Page document: hero
{
  heading: 'A page-specific heading',
  // Empty summary inherits "Default summary".
}

Fields copied into the consuming group are optional, even when the managed template requires them. On read, empty local values inherit from the managed template:

  • undefined, null, '', empty arrays, and empty plain objects inherit.
  • false, 0, and whitespace-only strings remain explicit local values.
  • Nested groups and tabs inherit field by field.
  • Arrays and blocks inherit as a whole only when empty. A non-empty local list is treated as the complete override.

Inheritance is read-time only. Fallback values are not written into the consuming document, so later edits to the managed template are reflected on the next API read. Admin edit forms receive the raw stored overrides. Empty supported inputs display the active locale's managed template value as a placeholder, and each template-backed group includes a localized link to edit that template document. The Admin API inspector still displays resolved values.

You can explicitly control resolution for Local API operations through Payload request context:

await payload.findByID({
  collection: 'pages',
  id,
  context: {
    templateFields: 'raw', // or 'resolved'
  },
});

An explicit context mode takes precedence over automatic Admin request detection. Template-backed fields cannot be nested inside a template definition.

Configuration

OptionTypeDefaultDescription
templatesTemplateConfig[]RequiredComplete set of managed template definitions.
enabledbooleantrueSet to false to leave the Payload config unchanged.

Each template has:

  • name: stable unique identifier containing only letters, numbers, and underscores.
  • label: admin document title.
  • fields: Payload fields shown for this template.
  • initialData: optional values applied only when the document is first created. Payload field defaults still apply.

Lifecycle and access

On Payload initialization, the plugin creates missing documents, updates labels, and deletes documents removed from configuration. Existing editable data is preserved. Renaming a template is treated as removing the old template and creating a new one.

Collection access prevents normal admin, REST, GraphQL, and access-controlled Local API users from creating or deleting template documents. The identity fields also deny user changes. As with every Payload collection, trusted Local API calls using the default overrideAccess: true bypass access control.

The package exports TemplateConfig, TemplateFieldConfig, and TemplatesPluginConfig from both the package root and @sittari/payload-templates/types.

Fetching a typed template

Create a lookup helper with the generated Template type from your project:

import config from '@payload-config';
import { createTemplateGetter } from '@sittari/payload-templates';
import { getPayload } from 'payload';

import type { Template } from './payload-types';

export const getTemplate = createTemplateGetter<Template>(() =>
  getPayload({ config }),
);

const notFound = await getTemplate('404');
// Typed as: { id: string | number; data_404?: Template['data_404'] } | null

Valid template names are inferred from the generated type's data_* properties. Each lookup filters by templateType and selects only the matching data_<name> group (plus Payload's always-selected document ID). It returns null when no configured document is found.

Similar plugins