Incorrect image link being served

Hi guys

First post here, and hopefully a stupid mistake on my end!

So basically, I am using the code below.

      <div class="container-small-white">
          <img class="imglogo" src="<?php echo $page->img1()->url(); ?>">

The blueprint is as below, as a Selector field

    label: Image 1
    type:  selector
    mode:  single
    width: 2/4
      - image

The image does not display, and when the element is inspected the browser is linking to rather than

When this is corrected in the the inspector in Chrome the image shows, so Iā€™m pretty sure its an issue with the Kirby code Iā€™m using

Any help would be greatly appreciated!

Hey, welcome to the forum.

The toFile() method is missing:

<div class="container-small-white">
  <img class="imglogo" src="<?= $page->img1()->toFile()->url(); ?>">

But this might break if the image is deleted at some point in time; better to check if you really have an image:

<?php if($image =  $page->img1()->toFile()): ?>
<img class="imglogo" src="<?= $image->url(); ?>">
<?php endif ?>
1 Like

Amazing. Thanks for the seriously quick reply!

One more actually ā€“ what would be the code if I wanted this image to link to another specific page on the site?

Wrap a link around it

<?php if($image =  $page->img1()->toFile()): ?>
<a href="<?= ($p = page('path_to_page'))? $p->url():''; ?>">
  <img class="imglogo" src="<?= $image->url(); ?>" alt="">
<?php endif ?>