The Image block allows you to upload an image OR use a public url.
The Page Sectionquery option lets me pull in whatever image I’d like but if the block image uses a URL instead of an uploaded file, no preview is shown.
How would I got about creating a simple preview image for use with Page Section from only an URL?
I don’t think this is possible out of the box because the image property expects a file object. I also tried with creating a file object or assets from a url, but that didn’t work either (does work on the frontend though), that’s probably because the Panel always creates thumbs instead of using a file. But even a File::version component that return the file didn’t help.
I guess you would have to overwrite the pages section, unless someone else has a better idea.
Oh, that stinks. I figured that since it was built to use external URLs, there’s got to be a way to preview those images too. Perhaps it’s relatively easy for the Kirby Devs to add something for this? Could make it a feature request.
That doesn’t make sense. Your method returns a lot of different things, sometimes an file object, sometimes a string, but in your query you try to convert it to a file object. And apart from that, the code has far too many unnecessary if-else statement.
I suppose
$this->page_thumbnail() is files field?
What is $this->cover() and why do you call the image() method on it?
then we have a block that can return either a file url or an image object
and then the background block where I have no idea what sort of field this contains
Could you please post the code snippets as code, not screenshots?
Good feedback. Thanks for clarifying. The page_thumbnail and cover are file fields that are used on certain pages and should override other thumbnails. The background block is basically a customized image block.
Using Ray() I can see it creates a file as expected, but the thumbnail is blank:
I tried using query: page.panel_thumbnail.toFile() and query: page.panel_thumbnail.
I can call $page->panel_thumbnail() in my template and it outputs the image as expected:
If cover is also a files field, then the cover part should be
if ($cover = $this->cover()->toFile()) {
return $cover;
}
Ah, I think I mentioned it before. The problem in the Panel is that the Panel needs a thumbnail, not the full image and the reason it worked in my testcode is that I had a file::version component in place that returns the full file object in these cases.
'components' => [
'file::version' => function ( $kirby, $file, array $options = []) {
static $original;
if ($file->filename() === 'panel.png') {
return $file;
}
if ($original === null) {
$original = $kirby->nativeComponent('file::version');
}
// and return it with the given options
return $original($kirby, $file, $options);
}
]