📄 Views

Displaying Blocks

Display Gutenberg content within a page

To allow Gutenberg blocks on your page, you'll need to do two things:

  • Ensure you've got a .graphql file which selects the contentBlocks field from the your post type.
  • Pass the contentBlocks field to the blocks prop of the <ContentBlocks /> component.

The ContentBlocks component is much like InnerBlocks, except that blocks are passed in as an array, rather than implictly.

views/page.graphql
query Page($postId: ID!) {
  page(id: $postId, idType: DATABASE_ID) {
    title
    slug
    template {
      templateName
    }
    contentBlocks
  }
}
views/page.jsx
import { Container } from "@components/layout/Grid"
import { defineView } from "eddev/views"
import { ContentBlocks } from "eddev"

export default defineView("page", (props) => {
  return (
    <Container>
      <h1>{props.title!}</h1>
      <ContentBlocks blocks={props.page?.contentBlocks} />
    </Container>
  )
})