mcoredev / tailor-blocks
Framework-agnostic PHP block content engine with YAML definitions and admin builder UI.
Requires
- php: ^8.2
- ext-intl: *
- symfony/yaml: ^7.0
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^11.0
README
Tailor Blocks is a framework-agnostic PHP content engine for structured block content. Blocks are defined in YAML, edited through the bundled browser editor, validated and normalized by PHP, stored as JSON by your CMS, and compiled into frontend-ready JSON.
Tailor Blocks is not a CMS. Your application owns routing, persistence, authentication, authorization, uploads, search persistence, and frontend rendering.
Requirements
- PHP 8.2+
- Composer
ext-intl
Installation
composer require mcoredev/tailor-blocks
Drop-in CMS Integration
For an existing CMS, use the endpoint-first drop-in flow:
- Publish assets from
vendor/mcoredev/tailor-blocks/dist/. - Add a
GETendpoint that returnsEditorMountConfigJSON. - Add a
POSTendpoint that sendseditor.sync()JSON throughTailorBlocksEngine::process(...). - Store normalized
content_jsonand derivedcompiled_json.
Start with the Drop-in CMS Integration guide and the copy-paste controller skeleton.
Assets
After Composer installation, copy or publish the built assets from
vendor/mcoredev/tailor-blocks/dist/ into a public admin asset directory:
mkdir -p public/assets/vendor/tailor-blocks
cp -R vendor/mcoredev/tailor-blocks/dist/* public/assets/vendor/tailor-blocks/
Production integrations should normally load the published all-in-one bundle:
<link rel="stylesheet" href="/assets/vendor/tailor-blocks/tailor-blocks.min.css"> <script src="/assets/vendor/tailor-blocks/tailor-blocks.min.js"></script>
For debugging or split loading, the package also ships:
tailor-blocks-core.min.jstailor-blocks-widgets.min.jstailor-blocks-editor.min.jstailor-blocks.js
The unminified split files are included for development and debugging.
Minimal PHP Usage
use TailorBlocks\Context\ContentContext; use TailorBlocks\Editor\EditorMountOptions; use TailorBlocks\EngineConfig; use TailorBlocks\ProcessOptions; use TailorBlocks\TailorBlocksEngine; $engine = TailorBlocksEngine::createFromDirectory( __DIR__ . '/definitions', EngineConfig::builder()->build(), ); $context = new ContentContext( siteKey: 'site-sk', permissions: ['content.edit'], ); $editorConfig = $engine->editorConfig( $storedContent, $context, EditorMountOptions::default() ->withOutputSelector('#content_json') ->withDefaultCommandShortcuts(), ); $processed = $engine->process( $submittedJson, $context, new ProcessOptions(strict: true, previousContent: $storedContent), );
Minimal Browser Usage
<link rel="stylesheet" href="/assets/vendor/tailor-blocks/tailor-blocks.min.css"> <div id="tailor-editor"></div> <textarea id="content_json" name="content_json" hidden></textarea> <script src="/assets/vendor/tailor-blocks/tailor-blocks.min.js"></script> <script> TailorBlocks.mount('#tailor-editor', editorConfig); </script>
License
MIT