pscheit / storyblok-php-richtext-renderer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Storyblok PHP Richtext Renderer

This package allows you to get an HTML string from the richtext field of Storyblok.

Install dependecies

composer require storyblok/richtext-resolver dev-master

Usage:

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 />'

How to define a custom schema for resolver?

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

Testing

We use phpunit for tests. You can execute the following task to run the tests:

composer run test

Contribution

Fork me on Github

About

License:MIT License


Languages

Language:PHP 100.0%