Extended image block not returning src value

Hello,

I am having an issue with an extended image block. Here is the content:

My layout in the panel in the site blueprint (for more cohesive UI for the client).
I need a query in the image block to get to a specific page images. Then I extend the image block such as this:

feedlayout:
	type: layout
	label: 'Feed Layout'
		layouts:
			- "1/2, 1/2"
		fieldsets:
			imageExtended:
				extends: blocks/image
				fields:
					image:
						label: 'Image'
						type: files
						query:  site.find("Projects").children.images
						upload: false

Everything is working fine in the panel, no worries about that.

However, when I set my template such as this:

<?php foreach ($site->feedlayout()->toLayouts() as $layout): ?>
	<div  class="grid__row">
		<?php foreach ($layout->columns() as $column): ?>
			<div class="grid__column<?= $column->blocks()->count() == 0 ? '--blank' : '' ?>" style="--columns: span <?= $column->span() ?>">
				<?php foreach ($column->blocks() as $block): ?>
					<div class="block">
						<?= $block ?>
					</div>
				<?php endforeach ?>
			</div>
		<?php endforeach ?>
	</div>
<?php endforeach ?>

and in a snippet called imageExtended.php located in site/snippets/blocks:

<?php
	if ($block->location() == 'web') {
		$src = $block->src()->esc();
	} elseif ($image = $block->image()->toFile()) {
		$src = $image->url();
	}
?>

<?php if ($src): ?>
	<figure>
		<img src="<?= $src ?>">
	</figure>
<?php else: ?>Src not found<?php endif ?>

It always return Src not found. I must have missed a step. I have done that multiple times in the past but for this project something is crashing but I couldn’t find…

Thanks a lot :slight_smile:

Oh I noticed that if I remove the query, it works. How can I make it work then with a query? :frowning:

Thanks a lot in advance!

Which Kirby version are you using?

What is actually stored in your content file for those images?

Hello!

I am using the 3.8.4 :slight_smile:

Here is the content of the site.txt

Feedlayout: [{"attrs":[],"columns":[{"blocks":[{"content":{"location":"kirby","image":["file:\/\/dssNAjKI81aBJdvD"],"src":"","alt":""},"id":"0d3e3b8d-2f57-44f7-8db0-0ee464390633","isHidden":false,"type":"imageExtended"}],"id":"5152b508-9643-4f51-80be-a3ec99c1785a","width":"1\/2"},{"blocks":[],"id":"7dec1b30-4354-40f1-bc23-2829d72cb115","width":"1\/2"}],"id":"dd7734e7-a8b4-4474-9a25-82c07ee291af"}]

and for the content of the project it is for the project:

Looks like this doesn’t return a file object for some reason
At the top of the file, d0

dump( $block->image());
dump( $block->image()->toFile());

Hey,

Here is what it returned:

Kirby\Cms\Field Object
(
    [image] => Array
        (
            [0] => file://dssNAjKI81aBJdvD
        )

)

Are your file ids still correct?

What if you add this code in a template somewhere, then open the page in the browser

$field = new Field(page(), 'test', ['file://dssNAjKI81aBJdvD']);

dump($field->toFile());

This should return a file object.

It doesn’t return anything… oh boy, I stepped on a pickle with this one haha :sweat_smile:

The file ID match this yes:

Feedlayout: [{"attrs":[],"columns":[{"blocks":[{"content":{"location":"kirby","image":["file:\/\/dssNAjKI81aBJdvD"],"src":"","alt":""},"id":"0d3e3b8d-2f57-44f7-8db0-0ee464390633","isHidden":false,"type":"imageExtended"}],"id":"5152b508-9643-4f51-80be-a3ec99c1785a","width":"1\/2"},{"blocks":[],"id":"7dec1b30-4354-40f1-bc23-2829d72cb115","width":"1\/2"}],"id":"dd7734e7-a8b4-4474-9a25-82c07ee291af"}]

Then please check if the uuid in your content file really matches the uuid stored for the file.

1 Like

Ok I found the reason. And that’s not Kirby at all. (???)

I reinstall MAMP and somehow it works now without changing anything… must have been something dealing with PHP version or I don’t what… that’s weird haha :flushed:

Thanks Sonja!