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.
Dynamic Value Rich Text Plugin for PayloadCMS
Installation
npm i @od-labs/payloadcms-dynamic-value-richtext1
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
Trends appear after 7 days of data. Daily snapshots have not started yet.
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
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1167287088-root)<a href="https://payloaddirectory.dev/plugins/1167287088-root"><img src="https://payloaddirectory.dev/badge/1167287088-root.svg" alt="Payload Directory"></a>README
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.
@ (default) or a custom character (like #).pnpm add @od-labs/payloadcms-dynamic-value-richtext
# or
npm install @od-labs/payloadcms-dynamic-value-richtext
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
})
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(),
],
}),
}
| Option | Type | Description |
|---|---|---|
collections | CollectionSlug[] | Automatically extract all text-based fields from these collections. |
globals | GlobalSlug[] | Automatically extract all text-based fields from these globals. |
fields | Field[] | Manually provide a list of Payload fields to be used as dynamic values. |
trigger | string | The character that triggers the autocomplete popup. Defaults to @. |
contact-info with a field email, it becomes available as contact-info.email.DecoratorNode in Lexical, which holds a reference to the field path (value) and the display label.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} />
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 })
To run the development environment:
pnpm install.env in the dev folder (see .env.example)pnpm devCreated & Owned by OD LABS. This plugin is open and free for use to all under the MIT License.
Contributions are welcome! If you have ideas for improvements or find any issues, feel free to open a Pull Request or create an Issue.
MIT
fullscreen editor
Fullscreen mode for the Payload Lexical rich text editor
680/wk114v3
richtext
Rich-text child block, default Lexical editor preset and JSX renderer for Atomic Payload
610/wk37v3
payload lexical typography
Lexical editor features for text color, font size, letter spacing, line height and font family
571.1k/wk109v?
payload paste as markdown
Lexical editor feature for pasting raw Markdown via a toolbar button, slash command, or drawer
570/wk0v3
payload editor
Preset-based, deterministic configuration builder for the Payload Lexical rich text editor
564/wk2v3
payload richtext lexical react native
React Native renderer for serialized Lexical rich text content from Payload CMS
420/wk0v3