I’m looking to extend the settings for the image block in the Kirby editor. The default image block has a modal with some options (alt text, link, css class). I’d like to add additional options like display size, and caption position.
What is the best way to do this? Create a new block that extends the image block functionality? Here is what a first attempt in that direction:
Hey @julienmillies, the code i was testing above works well. It seems to be the best way to add additional fields to the editor image block. All the files for the custom block live in a plugin folder. The documentation for making a block extension is here: https://github.com/getkirby/editor/wiki/Block-extensions
In addition to the documentation, these two files are key to setting up additional fields:
site/plugins/image-layout-block/index.js
// js file that registers your vue component, it should extend the default image block,
// and add your custom fields
site/plugins/image-layout-block/snippets/image-layout.php
// the front end template to generate the custom html for this block,
// the template has access to the custom fields via $attrs->yourfieldname()->value()
I want to extend the image block by fields like image-size and image-alignment. I’ve tried the solution above but it doesn’t work.
I created an image-layout-block folder in site/plugins and created this files:
The block is displayed in the panel and I can upload an image. But it does not render the image. When I delete the check if the block is empty I get the error that $src is not defined.
I hope you can help me. I’m also open for other solutions.
However I found that extending the Kirby editor was getting messy with too many files to keep track of, so I’m going to switch to using the Kirby Builder plugin instead.