This library provides Tiptap extensions for Storyblok’s RichText field, enabling seamless integration with the Tiptap for PHP library.
Branch | PHP | Code Coverage |
---|---|---|
main |
Ensure Composer is installed globally. If not, follow the Composer installation guide.
Run the following command in your project directory to install the latest stable version:
composer require storyblok/php-tiptap-extension
This package provides a Storyblok extension for Tiptap for PHP.
You need to create an Editor
instance and add the Storyblok extension:
use Tiptap\Editor;
use Storyblok\Tiptap\Extension\Storyblok;
$editor = new Editor([
'extensions' => [
new Storyblok(),
],
]);
$editor->setContent(['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Hello World']]]]);
echo $editor->getHTML();
You can customize how Storyblok blocks are rendered using the blokOptions
configuration.
use Tiptap\Editor;
use Storyblok\Tiptap\Extension\Storyblok;
$editor = new Editor([
'extensions' => [
new Storyblok([
'blokOptions' => [
'renderer' => function(array $value): string {
if ($value['component'] === 'custom_block_heading') {
return '<h1 class="red">' . htmlspecialchars($value['text']) . '</h1>';
}
return '';
},
]
]),
],
]);
$editor->setContent(['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Hello World']]]]);
echo $editor->getHTML();
You can disable specific Tiptap extensions within Storyblok.
use Tiptap\Editor;
use Storyblok\Tiptap\Extension\Storyblok;
$editor = new Editor([
'extensions' => [
new Storyblok([
'extensions' => [
'codeBlock' => false,
'heading' => false,
]
]),
],
]);
$editor->setContent(['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Hello World']]]]);
echo $editor->getHTML();
For a complete list of enabled extensions by default, check out Storyblok\Tiptap\Extension\Storyblok
.
This library is licensed under the MIT License. See the full license in the LICENSE file.
This library is built upon the Tiptap editor and the official Tiptap for PHP library.
Special thanks to SensioLabs for assisting with the initial implementation of the bundle.