The Blocks field is the perfect solution for complex single-column layouts and long-form text.
You can add the Blocks field to any fields section in your Panel like this:
|Sets the focus on this field when the form loads. Only the first field with this property gets focus.
|Default value for the field, which will be used when a page/file/user is created
|If true, the field is no longer editable and will not be saved
|Customize the default text when the blocks field is empty
|Defines the allowed block types in the blocks field. See below.
|Optional help text below the field
|The field label can be set as string or associative array with translations
|Maximum number of allowed blocks
|Minimum number of required blocks
|Saves pretty printed JSON in text files
|If true, the field has to be filled in correctly to be saved.
|If false, the field will be disabled in non-default languages and cannot be translated. This is only relevant in multi-language setups.
|Conditions when the field will be shown
|The width of the field in the field grid. Available widths:
By default, the block selector shows a single list of available block types in alphabetical order.
However, you can fully customize the selector for new block types with sorted block types and groups.
To change the order of available blocks, list them manually with the
You can group block types in the block selector for a better overview of the available options. This is particularly useful when your blocks lists gets longer once your start creating your own custom blocks.
To create such groups, use the Blocks field's generic "group" block type:
By default, all groups are open. With very long list, you might want to close groups of blocks that are used less frequently with the
open: false option:
You can set default blocks/values for blocks fields which will prepopulate the field using the
default prop. The
type property is required, but default blocks can be empty or filled with example content.
You can also set multiple default block entries:
Kirby's built-in blocktypes are not enough? Create your own! Check out our extensive documentation on custom block types, from basic to advanced:
- Modifying blocks types and custom blocks
- Custom block types
- Creating a custom block type from scratch
- Block factory: Creating your own blocks collection
- Nested blocks
Instead of manually creating previews for blocks types, you can use the
fields preview type to display the fields together with their content.
From modifying the output to how they are previewed in the Panel, you can also overwrite Kirby's built-in block types:
If you don't want to care about the HTML for each individual block, you can echo the entire blocks collection to render all blocks.
Looping through blocks to control their HTML can be very powerful. You can assign custom CSS classes, IDs for links and more.
You don't need to render the HTML for each individual block in the loop though. You can wrap the block with your custom HTML and then echo the
$block object to render the matching block snippet.
Sometimes you might wish to customize the way block snippets are loaded. Maybe you want to inject more snippet variables.
… or load snippets from a different location …
You can configure the default setup of your Blocks field in your config.php