Customizing core blocks
Learn the basics of modifying our core blocks and creating your own from scratch
A closer look at the blocks field
What makes a block?
A block type is made up of three components:
- A block blueprint which tells Kirby which fields should be available in the block
- A snippet to render the block content in the frontend
- An (optional) Panel preview for the WYSIWYG experience
You can find the source files for the existing block types in the documentation for each block type.
With this knowledge, we can go ahead and either modify existing block types or create new ones.
Extending core blocks
You can customize all existing block types to your needs in one or all of the following ways:
- Change how the block renders in the frontend by overwriting the snippet for the block
- Add or replace fields in a block type by overwriting the Blueprint file for the block type. This will often go hand in hand with modifying the output as in point 1.
- Change how the block looks in the Panel by overwriting its preview.
To modify a block, you can use the standard blueprints, snippets, and previews of each block type as a basis for your changes. Read more…
Let's modifiy the heading block to see how that works.
Example: extending the heading block
Modifying the block blueprint
Let's take the heading block and add a simple text field to add a custom ID for the heading
This will add the customID
field below the default fields of the block.
Extending existing fields in a block type
Instead of only adding new fields, you can also adjust the field settings for the default fields of the block.
Let's limit the number of heading levels for our heading block.
You can find all block fields and their settings in the docs for each block.
Adding tabs
You can extend our core blocks with additional tabs. Be aware though that you need to recreate all default fields in this case, as tabs will replace the default fields.
Block snippets
The HTML for each individual block is stored in its own block snippet. All our default block types bring their own snippets and can be overwritten. Block snippets are stored in /site/snippets/blocks
As an example, if you want to overwrite the snippet for our heading block, you would create a snippet file called /site/snippets/blocks/heading.php