# Cover image not found

**URL:** <https://forum.getkirby.com/t/cover-image-not-found/17352>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 20, 2020, 1:46pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352 "2020-02-20T13:46:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 1:46pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/1 "2020-02-20T13:46:39Z")

</div>

Kirby version: 3.3.4

Hi, I’m having an issue displaying a cover image. I had it working once but have obviously changed something and I can’t see whats wrong with the set up.

Any pointers appreciated, here’s the blueprints and template code:

**/site/blueprints/pages/home.yml**

```
# sidebar
sidebar:
	width: 1/3
	sections:
		sidebar_content:
			type: fields    
			fields:
				cover:
					extends: sections/image
					template: cover
					min: 1
					image:
						ratio: 1/1

```

**/site/blueprints/sections/image.yml**

```
label: Cover Image
type: files
headline: Cover Image
max: 1
layout: cards
info: "{{ file.dimensions }}"

```

**/site/templates/home.php**

```
<?php if ($cover = $page->images()->findBy("template", "cover")): ?>
  <?= $cover ?>
  <?php else: ?>
  <p>Cover image not found!</p>
<?php endif ?>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 20, 2020, 2:04pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/2 "2020-02-20T14:04:45Z")

</div>

And the image is really there?

---

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 3:25pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/3 "2020-02-20T15:25:07Z")

</div>

Yes 🙂

I was thinking I had a sticky cache, but flushed Chrome and tried Safari but no joy. I’m on MAMP.

---

<div class="post-metadata">

**Author:** ![jonasfeige](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jonasfeige/32/4550_2.png) [@jonasfeige](https://forum.getkirby.com/u/jonasfeige)\
**Post date:** [February 20, 2020, 3:32pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/4 "2020-02-20T15:32:36Z")

</div>

And does it really have the `cover` template?

---

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 4:04pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/5 "2020-02-20T16:04:54Z")

</div>

As far as I understand I don’t need a custom ‘cover.yml’ or template.

---

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 4:06pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/6 "2020-02-20T16:06:20Z")

</div>

I added the following code to test for the image file and I was able to print the cover image url:

```
if ($cover = $page->cover()->toFile()) {
    echo $cover->url();
}
```

---

<div class="post-metadata">

**Author:** ![jonasfeige](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jonasfeige/32/4550_2.png) [@jonasfeige](https://forum.getkirby.com/u/jonasfeige)\
**Post date:** [February 20, 2020, 4:12pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/7 "2020-02-20T16:12:03Z")

</div>

You don’t need a template, that’s true, but before you were searching for the cover via a `cover` template: `$cover = $page->images()->findBy("template", "cover")`.

You’re not doing that anymore, that’s why your new code works.  
You could rework your initial code to the following:

```
<?php if ($cover = $page->cover()->toFile()) : ?>
    <img src="<?= $cover->url() ?>" ?>
<?php else : ?>
    <p>Cover image not found!</p>
<?php endif ?>

```

It’s a different approach though. Before you were looking for the cover in all of the page’s images via a template, now you are checking a file field.

---

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 4:18pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/8 "2020-02-20T16:18:52Z")

</div>

Excellent, thanks that works and I would say targeting the file field is a more focused approach. But I guess each approach has its merits and depends on how you want to use the panel.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 20, 2020, 4:39pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/9 "2020-02-20T16:39:37Z")

</div>

If you have a field cover like you do in your blueprint, it makes sense to fetch the selected image from that field.

However, it is still strange that your first code snippet didn’t fetch the image because it should have (unless the image didn’t have the template assigned for some reason).

---

<div class="post-metadata">

**Author:** ![oppfield](https://avatars.discourse-cdn.com/v4/letter/o/cab0a1/32.png) [@oppfield](https://forum.getkirby.com/u/oppfield)\
**Post date:** [February 20, 2020, 5:07pm UTC](https://forum.getkirby.com/t/cover-image-not-found/17352/10 "2020-02-20T17:07:15Z")

</div>

Yes, I agree… particularly as I had it working at one point. I might create a new installation to test it out to try to understand what changed.
