PHP code example of mcoredev / tailor-blocks

1. Go to this page and download the library: Download mcoredev/tailor-blocks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mcoredev / tailor-blocks example snippets


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),
);