Hi,
I would like to modify the code block so it displays the filename or filepath. Example: Kirby CMS docs. What’s the best way to do this? Can i modify the default code block or should i create a custom code block with a plugin?
Adding a caption field to the default code block is easy, but i assume that it’s not possible to make it visible in the blocks editor?
A block can come with two separate parts for the Panel interface: A blueprint and a preview component. You can indeed update the blueprint quite easily and add a separate field for the caption/file path. But the preview component won’t know what to do with it. So users will have to edit the file path in the form view of the block.
If you want to improve the UX by integrating the caption field directly into the block preview, you can create a block plugin. Here you have two options: Either you override the default code
block in your plugin (useful if all code blocks on your site should use your custom component) or you register your block plugin with a different name (such as code-extended
).