Kirby Blocks as HTML in Rest API

Hi !

I’m playing with Kirby CMS and using it as a headless CMS. I’m using Blocks field to handle rich content. In the API, this field is returned as an array of objects:

[
    {
        "content": {
            "level": "h2",
            "text": "test"
        },
        "id": "02d4a71b-cd02-4382-a78c-84ff1e68324b",
        "isHidden": false,
        "type": "heading"
    }
]

Which is great, I think. But in my case, it’s annoying, as I should do all the rendering by myself in my React app.

Is there a way, or an option, to tell Kirby to render this field as HTML content when it’s returned via its API?

I know there is a $blocks->toHtml() method, but I’m using a standalone React frontend, so I can’t use this in my JSX.

1 Like