Skip to content

feat: add dynamic content variables / inline tokens#743

Merged
lane711 merged 1 commit intomainfrom
fix/issue-719
Apr 5, 2026
Merged

feat: add dynamic content variables / inline tokens#743
lane711 merged 1 commit intomainfrom
fix/issue-719

Conversation

@lane711
Copy link
Copy Markdown
Collaborator

@lane711 lane711 commented Apr 3, 2026

Summary

Adds a Global Variables plugin that enables dynamic content variables (inline tokens) in rich text fields. Variables are stored as key-value pairs and referenced using {variable_key} syntax, with server-side resolution when content is read via the API.

This implements Part 1 (Global Variables Collection) and Part 3 (Server-Side Resolution) from #719. Part 2 (Quill editor UI for token picker) is planned for a follow-up PR.

Changes

  • New global-variables-plugin — core plugin with:
    • global_variables SQLite table (key, value, description, category, is_active)
    • Full CRUD API: GET/POST/PUT/DELETE /api/global-variables
    • GET /api/global-variables/resolve endpoint for flat key→value map
    • Admin page at /admin/global-variables
    • In-memory cache with 5-minute TTL
    • Plugin bootstrap registration
  • Variable resolver service — recursive {variable_key} token replacement in strings, objects, and arrays
  • Content read integrationGET /api/content/:id now resolves variables in content data (opt-out via ?resolve_variables=false)
  • CONTENT_READ hook — new hook type added to the HOOKS constant for plugin extensibility
  • 13 unit tests for the variable resolver (all passing)

Testing

  • All 56 test files pass (1412 tests total)
  • TypeScript type-check passes
  • New tests cover: single/multiple token replacement, unresolved tokens, nested objects, arrays, edge cases

Caveats

  • Part 2 (Quill editor UI with token picker / autocomplete) is not included — this is a UI-heavy feature better suited for a dedicated follow-up PR
  • Resolution only applies to GET /api/content/:id — list endpoints can be extended in future
  • Variable keys are restricted to [a-z0-9_] to avoid conflicts with HTML/JSON syntax

Fixes #719

Adds a Global Variables plugin that enables dynamic content variables
(inline tokens) in rich text fields. Variables stored as key-value pairs
are referenced using {variable_key} syntax and resolved server-side
when content is read via the API.

Changes:
- New global-variables-plugin with CRUD API and admin UI
- Variable resolver service with recursive object traversal
- content:read hook type added to HOOKS constant
- Server-side resolution integrated into content GET endpoint
- In-memory caching for variable lookups (5min TTL)
- 13 unit tests for the variable resolver

Part 2 (Quill editor UI for token picker) is planned for a follow-up PR.

Fixes #719

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lane711 lane711 merged commit 9ab336a into main Apr 5, 2026
2 checks passed
@cp-bwg
Copy link
Copy Markdown
Contributor

cp-bwg commented Apr 6, 2026

Would like to add a candidate for a phase 4 - the ability to register functions to these global variables. Think of a calculation of total reviews count, or an api call to calculate something. Internal db relationship resolver, etc. just like a Wordpress short code registry really.

cp-bwg added a commit to cp-bwg/sonicjs that referenced this pull request Apr 8, 2026
…des plugins (SonicJs-Org#756)

Implements Part 2 (Rich Text Inline Tokens) from SonicJs-Org#719:

- Enhanced global-variables-plugin with full CRUD admin page, Quill blots
  (blue chips), TinyMCE PluginManager integration, and editor toggle
- New shortcodes-plugin with [[shortcode]] syntax, handler registry,
  CRUD admin, live preview, Quill blots (purple chips), and TinyMCE support
- Shared editor utilities: Quill constructor Proxy, searchable picker
  dropdown, TinyMCE PluginManager approach, admin HTML template
- Content resolution: variables (priority 50) → shortcodes (priority 60)
- 5 built-in shortcode handlers: current_date, phone_link, cta_button,
  plan_count, provider_rating

Closes SonicJs-Org#719
Extends SonicJs-Org#743

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lane711 pushed a commit that referenced this pull request Apr 9, 2026
…des plugins (#756)

Implements Part 2 (Rich Text Inline Tokens) from #719:

- Enhanced global-variables-plugin with full CRUD admin page, Quill blots
  (blue chips), TinyMCE PluginManager integration, and editor toggle
- New shortcodes-plugin with [[shortcode]] syntax, handler registry,
  CRUD admin, live preview, Quill blots (purple chips), and TinyMCE support
- Shared editor utilities: Quill constructor Proxy, searchable picker
  dropdown, TinyMCE PluginManager approach, admin HTML template
- Content resolution: variables (priority 50) → shortcodes (priority 60)
- 5 built-in shortcode handlers: current_date, phone_link, cta_button,
  plan_count, provider_rating

Closes #719
Extends #743

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Dynamic content variables / inline tokens in rich text

2 participants