Files (images) not appearing in panel after importing content from older installation

I have a very old installation of a Kirby 2 powered website that I’m (finally!) updating. I want to do a redesign of the website at the same time, so to start with I am trying to import the old content into the Kirby Starterkit and I’ll take it further from there.

I’ve managed to successfully import pages (I still have to get the panel fields right but I think I can manage that), but the images I imported are not appearing in the panel.

This is the the panel home page (site page):

This is the panel page for a news post, where under files it says there are no files yet:

This is the folder structure:

These are the file permissions (files are 644):

This is what the post looks like on the website (the file shows up):

Does anybody know what I might be doing wrong? Thanks!

Could you please post the blueprint for that page?

Of course. The blueprint for the page is this (as you can see I have changed very little from the Starterkit note template):

# Each page blueprint must have a title, the title may be different from the file name
title: Article

# Sorting number scheme that is applied when page status is changed to `listed`
# More about page sorting: https://getkirby.com/docs/reference/panel/blueprints/page#sorting
num: date

# Each page can have an icon that is shown in page listings when no preview image is available.
icon: 📖

# Custom descriptions for each page status depending on use case
# More about page status: https://getkirby.com/docs/reference/panel/blueprints/page#statuses
status:
  draft:
    label: Draft
    text: The note is still in draft mode. It can only be seen by editors with panel access.
  unlisted:
    label: In Review
    text: The note is online and can be visited with the direct URL. The team must still give the final go to publish it.
  listed:
    label: Published
    text: The note is online and listed in the blog

# Define the form layout with two columns
# Columns are optional but help structure the form layout
# More about columns: https://getkirby.com/docs/guide/blueprints/layout#defining-columns
columns:
  - width: 2/3
    # This columns only has a single field
    fields:
      text:
        type: blocks

  - width: 1/3
    # This second column holds a fields section with multiple fields
    # More about fields sections: https://getkirby.com/docs/reference/panel/sections/fields
    sections:
      meta:
        type: fields
        fields:
          # If you need the same field in multiple locations, you can define them once and reuse whereever needed.
          # Here we use a files field defined in `/site/blueprints/field/cover.yml`
          cover: fields/cover
          date:
            type: date
            time: true
            default: now
          author:
            type: users
          # Fields types can be added using the shortcut `fieldname: true`
          # (however, you can only use a fieldname once per page and this only makes sense for simple fields without configuration)
          tags: true
      files:
        type: files
        template: blocks/image

I haven’t changed the blocks/image.yml blueprint or the files/image.yml blueprint from the Starterkit.

This template is very likely not assigned to your imported images, that would explain why they are not showing up.

Either remove the template property, or assign this template manually or programmatically to your images.

template is a filter that allows you to have files in different files sections if needed. If you don’t need the filter, remove it.

Thank you! I am trying to write a script to assign the template to the images, but I’m not having much luck.

Is there a page in the docs that has information about how to do things like this?

What I’ve tried is this, which I called assignfiletemplates.php:

<?php

// Load Kirby
require_once 'kirby/bootstrap.php';

$kirby = new Kirby();

$kirby->impersonate('kirby');

$images = $kirby->$site()->$index()->files()->images();

try {
    foreach ($images() as $image) {
        if(!$image->template()) {
          $image->update([
            'template' => 'image'
          ]);
          echo "Template 'image' assigned to: " . $image->filename() . "\n";
        }
    }

} catch (Exception $e) {
    echo "Failed to assign template. Error: " . $e->getMessage() . "\n";
}

This is the error message I get:

Whoops\Exception\ErrorException: Undefined variable $site in /Users/robin/Library/CloudStorage/Dropbox/DAVL/website/assignfiletemplates.php:10
Stack trace:
#0 /Users/robin/Library/CloudStorage/Dropbox/DAVL/website/assignfiletemplates.php(10): Whoops\Run->handleError(2, 'Undefined varia...', '/Users/robin/Li...', 10)
#1 {main}
Whoops\Exception\ErrorException: Undefined variable $site in file /Users/robin/Library/CloudStorage/Dropbox/DAVL/website/assignfiletemplates.php on line 10
Stack trace:
  1. Whoops\Exception\ErrorException->() /Users/robin/Library/CloudStorage/Dropbox/DAVL/website/assignfiletemplates.php:10
  2. Whoops\Run->handleError() /Users/robin/Library/CloudStorage/Dropbox/DAVL/website/assignfiletemplates.php:10

This cannot possibly work.

$images = $kirby->site()->index()->images();

In your blueprint, you use blocks/image, so either change that in your blueprint or change it to blocks/image here.

1 Like

Thank you! This solved the problem.

Just a question, which I think is related. Since I imported these files from an old Kirby installation, none of them have UUIDs. I can’t seem to figure it out from the docs: is there a way to assign UUIDs to files somehow?

Sorry to bother again, I thought the issue was solved, but I am actually still encountering the problem with missing images. Ping @texnixe, I hope that’s okay.

I’ve managed to assign UUIDs and the correct template to all the image files.

The images show up in the panel on the site page:

However the images do not show up in the panel on the article page:

They do get loaded in the template, though:

This is the folder structure (and image metadata):

This is the article blueprint, article.yml:

# Each page blueprint must have a title, the title may be different from the file name
title: Article

# Sorting number scheme that is applied when page status is changed to `listed`
# More about page sorting: https://getkirby.com/docs/reference/panel/blueprints/page#sorting
num: date

# Each page can have an icon that is shown in page listings when no preview image is available.
icon: 📄

# Custom descriptions for each page status depending on use case
# More about page status: https://getkirby.com/docs/reference/panel/blueprints/page#statuses
status:
  draft:
    label: Concept
    text: Het artikel is een concept en nog niet gepubliceerd. Het kan alleen worden gezien in het panel.
  listed:
    label: Gepubliceerd
    text: Het artikel staat op de website en kan worden gezien door bezoekers.

# Define the form layout with two columns
# Columns are optional but help structure the form layout
# More about columns: https://getkirby.com/docs/guide/blueprints/layout#defining-columns
columns:
  - width: 1/3
    # This column only has a single field
    fields:
      text:
        type: writer
        label: Tekst

  - width: 1/3
    fields:
      images:
        type: files
        template: blocks/image
        label: Afbeeldingen

  - width: 1/3
    # This second column holds a fields section with multiple fields
    # More about fields sections: https://getkirby.com/docs/reference/panel/sections/fields
    sections:
      meta:
        type: fields
        fields:
          date:
            type: date
            time: true
            default: now
            label: Datum
          # Fields types can be added using the shortcut `fieldname: true`
          # (however, you can only use a fieldname once per page and this only makes sense for simple fields without configuration)
          tags: true

This is the image blueprint, image.yml:

# Each file blueprint must have a title, the title may be different from the file name
title: Image

# Like page blueprints, file blueprints can define a layout with tabs, columns, sections and fields
# File blueprints define what sort of information should get stored in a file's meta data file
# In addition to the fields defined in this example blueprint, you can also set what type of file is acceptable
# when this blueprint is used, which allows you to control what users can upload.
# More about file blueprints: https://getkirby.com/docs/reference/panel/blueprints/file

accept: 
  type: image

columns:
  - width: 1/2
    sections:
      content:
        type: fields
        fields:
          caption:
            label: Opschrift
            type: textarea
            size: medium
  - width: 1/2
    sections:
      meta:
        type: fields
        fields:
          alt:
            label: Alt text (beschrijving van de  afbeelding) 
            type: text

blocks/image.yml just extends files/image.