In one of our previous posts, we saw how to retrieve all the registered blocks in Gutenberg. It was pretty easy because Gutenberg provides an API out of the box.
However, to retrieve the list of block patterns, we have to do a little more work as Gutenberg doesn’t have an API yet.
Block Patterns reside under the
core/block-editor data store, and this is how we can access them:
The above snippet uses ES6 and the @wordpress package.
You can retrieve block patterns directly from the
wp global object as well!
Add a new post or open an existing one, open the browser dev console and run the following:
That’s it! Thank you for reading 😀