KQL plugin : how to get the image URL from the image block?


I use the KQL plugin to get data from a JSON. When I query blocks, I don’t see the URL from an image blocks. How to get the image url?

The equivalent in PHP to :

<?php if ($image = $block->image()->toFile()): ?>
<?= $image->url() ?>
<?php endif; ?>

This is what my JSON file return from the image block (“Kirby” location selected) :

              "blocks": [
                  "content": {
                    "location": "kirby",
                    "image": [
                    "src": "",
                    "alt": "",
                    "caption": null,
                    "link": "",
                    "ratio": "",
                    "crop": "false",
                    "classatt": "",
                    "idatt": ""
                  "id": "4171a968-1c1b-41b4-b42d-87c2ac9f922f",
                  "isHidden": false,
                  "type": "image"
              "id": "a8d111bf-d281-4c0c-b4be-609f507bac08",
              "width": "1/3"
1 Like

I also have the same question. I use kirby headless so I would like to get the file url.

Is there a way to change what the image block returns?
I think one way would be to write my custom block (Creating a custom block type from scratch | Kirby CMS) where I define that return values should include the fill image path (also giving me the power to resize and crop the images how I want).

But if I could just override and customize the default image block type, that would be even better…

Thanks for any thoughts about that idea.

Yes you can :slight_smile:

Yeah but that did not do it. (Well, the link does at least not explain how to do that.) I needed to update some fields on the update hook.
The solution is discussed in depth here:

So yeah, in the end I used the default image block and saved the full path programmatically.

But thanks for getting back to me.