This package allows you to get an HTML string from the richtext field of Storyblok.
You can install the Storyblok PHP Richtext Renderer via composer. Storyblok PHP Richtext Renderer requires PHP version 7.3 to 8.2. The suggestion is to use an actively supported version of PHP (8.1 and 8.2).
If you want to install the stable release of Storyblok PHP Richtext Renderer you can launch:
composer require storyblok/richtext-resolver
If you want to install the current development release, you can add the version dev-master
:
composer require storyblok/richtext-resolver dev-master
For executing the command above, you need to have composer installed on your development environment. If you need to install Composer, you can follow the official Composer documentation:
- Install Composer on GNU Linux / Unix / macOS
- Install Composer on Windows
We suggest using the latest version of PHP.
composer require storyblok/richtext-resolver dev-master
Instantiate the Resolver
class:
use Storyblok\RichtextRender\Resolver;
$resolver = new Resolver();
Use the function render()
to get the html string from your richtext field.
// previous code...
// Note that in php our objects use multidimensional array notation
$data = [
"type" => "doc",
"content" => [
[
"type" => "horizontal_rule"
]
]
];
$resolver->render($data) # renders a html string: '<hr />'
Make a copy of the default schema storyblok-php-richtext-renderer/src/Schema.php and add your own schema as parameter to the Richtext class.
$resolver = new Resolver($my_custom_schema);
We use PHPUnit for tests. You can execute the following composer task to run the tests:
composer run test
If you want to generate the coverage report you can launch:
composer run test-coverage
You will find the HTML reports in the coverage/
directory.
For consistency, we are using PHP Coding Standards Fixer tool, for checking and fixing the code to follow standards.
For checking the code you can execute:
composer run codestyle-check
If you want to automatically fix the code to follow standards:
composer run codestyle-fix
If you want to execute fix and test coverage:
composer run all-check
Fork me on Github