Adding new Content block (Layout Builder)
How to add new Content block (Layout Builder)?
Content blocks are used in many places, primarily in Layout Builder, but also in Page Builder content blocks (inside the Grid block, for example), in articles, Default template page, and other places.
Creating new Content block
To add a new Content block you must do the next steps:
Add new block blueprint: site/theme/blueprints/blocks/yourblockname.yml
Add new block snippet: site/theme/snippets/blocks/yourblockname.php
After that just code that files, to do what you want them to do
Including new Content block
To include your new block to be available inside the panel:
If you want to add that block to Layout Builder
Copy site/plugins/zero-one/blueprints/sections/layout-builder.yml to site/theme/blueprints/sections/layout-builder.yml and add your block name to the fieldsets blocks list
If you want to add that block to Content blocks fields throughout the website:
Copy site/plugins/zero-one/blueprints/fields/blockEditor.yml to site/theme/blueprints/fields/blockEditor.yml and add your block name to the fieldsets blocks list
If you want that block to the Article template
Copy site/plugins/zero-one/blueprints/pages/article.yml to site/theme/blueprints/pages/article.yml and add your block name to the fieldsets blocks list
And that's it. Your custom block will be available. Only, it will have the default simple preview in the panel. If you want to create a better block preview you will have to create a simple plugin for that. Check this Kirby docs Cookbook recipe and check site/plugins/zero-one/index.js on how we built some previews.
Last updated
Was this helpful?