Page not loading because of empty image field

Hi everyone,

I’m trying to add an image to the page to be the “hereo image” I’ve decided to put it as my default page template because it’s the most widely used template for my site, for now at least.

I understand I need some sort of IF statement and I’ve used these two threads to get me this far.

https://forum.getkirby.com/t/select-one-image-to-be-the-hero-image-of-a-page/4109

<!-- if statement goes in here***-->
    <div>
    	<img src=<?php echo $page->image($page->coverImage()->value())->url() ?> />
    </div>
<!-- ***Ends here*** -->

    <div class="text">
      	<h1><?php echo $page->title()->html() ?></h1>
      	<?php echo $page->text()->kirbytext() ?>
    </div>
1 Like

Yes, you check if the image exists like this:

<?php
if($image = $page->coverImage()->toFile()): ?>
    <div>
    	<img src="<?php echo $image->url() ?>">
    </div>
<?php endif ?>

    <div class="text">
      	<h1><?php echo $page->title()->html() ?></h1>
      	<?php echo $page->text()->kirbytext() ?>
    </div>
1 Like

Thank you :grinning: