I’d like to show a custom page preview image (a.k.a. page thumbnail) from a field called “post_image”, and if not specified, the first image (as is default). I’ve got the first part right but don’t know how to do the alternative. This works but, of course, doesn’t show a fallback:
but that doesn’t even show the custom image anymore. I also tried
image: page.post_image.or(page.image).toFile
and similar things but the fallback default first image isn’t shown. What am I doing wrong? What’s the default function for retrieving the first image, anyway?
But I’m probably stupid, I couldn’t get this to work with my setup.
I have a page called ideas.yml containing a file field named “post_image” and have now created a file called “ideas.php” in /site/models. In this file I have:
class IdeasPage extends Page {
public function previewImage() {
return $this->content()->get('post_image')->toFile() ?? $this->image();
}
}
Ah, thank you so much, it works now. Incidentally the same idea crossed my mind but I wasn’t too sure because my PHP skills are pretty limited. Thanks again for your prompt response.