Return parsed block content when querying pages from REST export

Created on 14 September 2021, over 3 years ago
Updated 27 December 2023, about 1 year ago

When displaying the content of a Gutenberg page via a custom REST export from Views, is there any way to display the content as an array of objects parsed from the HTML-commented Gutenberg string? For example, if I were to create a page with a simple paragraph block:

<!-- wp:paragraph {
    "placeholder":"Summary",
    "textColor":"accent",
    "backgroundColor":"secondary"
} -->
<p class="has-text-color has-background has-accent-color has-secondary-background-color">
This is a new paragraph.
</p>
<!-- /wp:paragraph -->

Could I return something from the REST export that looks more like this:

  [
    {
      blockName: "core/paragraph",
      attrs: [
        {
          placeholder: "Summary",
          textColor: "accent",
          backgroundColor: "secondary"
        }
       ],
      innerBlocks: [],
      innerHTML: '<p class="has-text-color has-background has-accent-color has-secondary-background-color">This is a new paragraph.</p>',
      innerContent: [
        '<p class="has-text-color has-background has-accent-color has-secondary-background-color">This is a new paragraph.</p>'
       ]
  ]

In WordPress, I've generally had success with by using the parse_blocks function with filters.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024