ZNAXNOR

Payloadcms Dynamic Value Richtext Plugin

by ZNAXNOR
Rich text & editors
v3
^3.37.0
MIT

Overview

Summary generated from the README

Adds a Lexical feature that lets editors insert variables referencing field values from chosen collections, globals or manually defined fields. Typing a trigger character such as @ opens an autocomplete list, and the chosen variable appears as a non-editable badge. Frontend rendering needs the plugin's JSX converters or its wrapper component. Requires Payload 3.37 or later.

Features

  • Inline autocomplete opened by a configurable trigger character
  • Variables shown as non-editable badges that delete as a single unit
  • Fields pulled automatically from collections and globals, or defined manually
  • Copy and paste of dynamic values between editors and documents
  • React wrapper component and JSX converters for frontend rendering
  • Optional resolution of values from real document data at render time

Use cases

  • Reuse company contact details across pages without retyping them in rich text
  • Keep shared values such as site names consistent by referencing a global field
  • Render rich text on a Next.js frontend with variables resolved from document data

From the author

Dynamic Value Rich Text Plugin for PayloadCMS

Installation

npm i @od-labs/payloadcms-dynamic-value-richtext

1

Stars

0

Forks

1

Open Issues

7 months ago

Last Updated

0

Weekly Downloads

v1.1.0

npm Version

112.9 KB

Unpacked Size

1

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

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

Health Score

27/100Fair

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/1167287088-root.svg)](https://payloaddirectory.dev/plugins/1167287088-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1167287088-root"><img src="https://payloaddirectory.dev/badge/1167287088-root.svg" alt="Payload Directory"></a>
Updated Mar 2, 2026Created Feb 26, 2026Published Mar 2, 2026

README

Payload Dynamic Value Rich Text Plugin

A powerful Payload CMS plugin for the Lexical editor that allows you to designate field values as dynamic variables. These variables can be reused throughout your rich text content and are visually represented as interactive badges.

Features

  • Inline Autocomplete: Trigger a searchable list of available dynamic fields using @ (default) or a custom character (like #).
  • Visual Badges: Variables appear in the editor as clean, non-editable badges with a "VAR" prefix, making them distinct from regular text.
  • Automatic Field Resolution: Pull fields automatically from specified Collections and Globals, or provide manually defined fields.
  • Unit Tokenization: Variables are treated as single units—selecting or deleting them happens in a single action.
  • Clipboard Support: Copy and paste dynamic values between editors or documents while maintaining their data integrity.
  • Light & Dark Mode: Seamlessly integrates with Payload's admin UI theme.

Installation

pnpm add @od-labs/payloadcms-dynamic-value-richtext
# or
npm install @od-labs/payloadcms-dynamic-value-richtext

Basic Setup

Add the plugin to your payload.config.ts:

import { buildConfig } from 'payload'
import { dynamicValuePlugin } from '@od-labs/payloadcms-dynamic-value-richtext'

export default buildConfig({
  plugins: [
    dynamicValuePlugin({
      collections: ['company-settings', 'sites'],
      globals: ['contact-info'],
      trigger: '@',
    }),
  ],
  // ... rest of config
})

Configuration

In your Lexical editor configuration, add the DynamicValueFeature to your list of features:

import { DynamicValueFeature } from '@od-labs/payloadcms-dynamic-value-richtext'

// In your collection/global field definition:
{
  name: 'content',
  type: 'richText',
  editor: lexicalEditor({
    features: ({ defaultFeatures }) => [
      ...defaultFeatures,
      DynamicValueFeature(),
    ],
  }),
}

Plugin Options

OptionTypeDescription
collectionsCollectionSlug[]Automatically extract all text-based fields from these collections.
globalsGlobalSlug[]Automatically extract all text-based fields from these globals.
fieldsField[]Manually provide a list of Payload fields to be used as dynamic values.
triggerstringThe character that triggers the autocomplete popup. Defaults to @.

How it Works

  1. Resolution: The plugin recursively flattens the fields of your chosen collections and globals. For example, if you have a Global contact-info with a field email, it becomes available as contact-info.email.
  2. Injection: When you type the trigger character in the editor, a popup appears showing all available fields.
  3. Storage: The variable is stored as a custom DecoratorNode in Lexical, which holds a reference to the field path (value) and the display label.

Frontend Rendering (Important)

If you render Lexical content on your website with RichText, you must provide this plugin's JSX converters. Without this, Payload will show custom nodes as unknown node.

Use the plugin-provided wrapper component that injects converters for you:

import { DynamicValueRichText } from '@od-labs/payloadcms-dynamic-value-richtext/react'

<DynamicValueRichText data={page.content} payloadData={page} />

Option B: manual converters

import { RichText } from '@payloadcms/richtext-lexical/react'
import { DynamicValueJSXConverters } from '@od-labs/payloadcms-dynamic-value-richtext/jsx'

<RichText data={page.content} converters={DynamicValueJSXConverters} />

If you want to resolve the dynamic value from real document data at render time:

import { createDynamicValueJSXConverters } from '@od-labs/payloadcms-dynamic-value-richtext/jsx'

const converters = createDynamicValueJSXConverters({ data: page })

Development

To run the development environment:

  1. Clone the repository
  2. Install dependencies: pnpm install
  3. Create a .env in the dev folder (see .env.example)
  4. Run development: pnpm dev

Ownership

Created & Owned by OD LABS. This plugin is open and free for use to all under the MIT License.

Contributions

Contributions are welcome! If you have ideas for improvements or find any issues, feel free to open a Pull Request or create an Issue.

License

MIT

Similar plugins