# Saved image unavailable in template

**URL:** <https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 20, 2021, 3:01pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867 "2021-01-20T15:01:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![herrbischoff](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/herrbischoff/32/9403_2.png) [@herrbischoff](https://forum.getkirby.com/u/herrbischoff)\
**Post date:** [January 20, 2021, 3:01pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/1 "2021-01-20T15:01:50Z")

</div>

I have set up the following blueprint and want to output the URL of the single image saved via the panel. However, there is no output. All text fields work properly but there’s no output for the filename.

```auto
title: News

columns:
  main:
    width: 2/3
    sections:
      description:
        type: fields
        fields:
          text:
            type: textarea
            size: large
            required: true
  sidebar:
    width: 1/3
    sections:
      meta:
        type: fields
        fields:
          date:
            label:
              en: Date
              de: Datum
            type: date
            time: true
            default: today
            required: true
      cover:
        type: files
        headline:
          en: Image
          de: Bild
        layout: cards
        template: news
        uploads: news
        max: 1
        info: "{{ file.dimensions }}"
        image:
          cover: true

```

According to the documentation

```auto
echo $page->cover()->toFile()->url();

```

should do it but the output is empty. I do not understand what it is that I’m doing wrong. Maybe someone can shine a little light on why this is and what I need to do to make it work.

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [January 20, 2021, 3:30pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/2 "2021-01-20T15:30:24Z")

</div>

The code you use is not recommended because you always have to check for an object:

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

```

---

<div class="post-metadata">

**Author:** ![herrbischoff](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/herrbischoff/32/9403_2.png) [@herrbischoff](https://forum.getkirby.com/u/herrbischoff)\
**Post date:** [January 20, 2021, 3:35pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/3 "2021-01-20T15:35:55Z")

</div>

Thanks for pointing that out but this of course still outputs nothing since the result is empty. I’d like to know why that is and how to rectify it. Any ideas?

---

<div class="post-metadata">

**Author:** ![bruno](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bruno/32/6422_2.png) [@bruno](https://forum.getkirby.com/u/bruno)\
**Post date:** [January 20, 2021, 4:30pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/4 "2021-01-20T16:30:34Z")

</div>

I remember I had a similar thing once, I don’t remember what it was exactly, might be a different thing but try renaming the `cover` field to something else like `coverImage`

---

<div class="post-metadata">

**Author:** ![herrbischoff](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/herrbischoff/32/9403_2.png) [@herrbischoff](https://forum.getkirby.com/u/herrbischoff)\
**Post date:** [January 20, 2021, 4:42pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/5 "2021-01-20T16:42:03Z")

</div>

Sadly this does not do anything.

What I’ve noticed is that the image reference is not reflected in the relevant content text file:

```auto
Title: This is the title.

----

Text:

This is some text.

----

Date: 2021-01-19 13:20

```

In the panel, the image is saved and displayed fine but does not appear in the file. This is probably not expected behaviour. I’m at a loss.

---

<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:** [January 20, 2021, 6:14pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/6 "2021-01-20T18:14:13Z")

</div>

You use a section instead of a field and a section doesn’t store anything in content

You could nevertheless fetch this image by template

```auto
if ( $image = $page->files()->template('news')->first() ) {
  echo $image->url();
}

```

Or you convert your section into a field.

---

<div class="post-metadata">

**Author:** ![herrbischoff](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/herrbischoff/32/9403_2.png) [@herrbischoff](https://forum.getkirby.com/u/herrbischoff)\
**Post date:** [January 20, 2021, 9:25pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/7 "2021-01-20T21:25:52Z")

</div>

Thanks. I’d rather do it the correct way, which is probably converting the section into a field.

Would you mind explaining a bit more about this? I couldn’t find anything concrete in the documentation explaining in plain English some of those simple use cases. Most samples appear to use presets and modify certain aspects instead of demonstrating a full page blueprint with columns. I always learn better by example and by understanding the underlying concepts.

---

<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:** [January 20, 2021, 9:45pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/8 "2021-01-20T21:45:49Z")

</div>

You can find quite a few annotated blueprint examples in the Starterkit. There are also example here: [Samples | Kirby](https://getkirby.com/docs/reference/panel/samples)

Difference between fields and sections : [Kirby in a nutshell | Kirby](https://getkirby.com/docs/cookbook/setup/kirby-in-a-nutshell#sections-or-fields)

Your sidebar setup currently looks like this (shortened)

```auto
  sidebar:
    width: 1/3
    sections:
      meta:
        type: fields
        fields:
          #... fields here
      cover:
        type: files
        headline:
          en: Image
          de: Bild

```

So under sections you have meta and cover, which makes them both sections.

If you indent your cover section to move it inside the fields section, you have a field

```auto
  sidebar:
    width: 1/3
    sections:
      meta:
        type: fields
        fields:
          # ... fields here
          cover:
            type: files
            label: # a field has a label, not a headline
              en: Image
              de: Bild

```

We also have to rename `headline` to `label` for a field.

---

<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:** [January 20, 2021, 9:53pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/9 "2021-01-20T21:53:31Z")

</div>

> [@herrbischoff](#):
>
> I’d rather do it the correct way,

That’s not so much a matter of one thing being more correct than the other, just different things for different use cases.

Think of the files/pages/users fields as specialized (multi)select fields.

---

<div class="post-metadata">

**Author:** ![herrbischoff](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/herrbischoff/32/9403_2.png) [@herrbischoff](https://forum.getkirby.com/u/herrbischoff)\
**Post date:** [January 21, 2021, 1:32pm UTC](https://forum.getkirby.com/t/saved-image-unavailable-in-template/20867/10 "2021-01-21T13:32:02Z")

</div>

Fantastic, thank you. Your hint regarding converting the section to a field put me on the right track. Good to see your addition confirm my current solution. I’m still confused about sections vs. fields, regarding why I would ever need/want to use a section.

The inner workings of Kirby are confusing in some places, yet I get the impression it’s that way to allow for extreme flexibility. Which is probably useful for advanced solutions but hard to get started with. I’m slowly chewing myself through…
