Default file blueprint applied half way

I have an odd issue: When I upload a file using a default super basic files field, the default files blueprint is used, but only half way.

Given this field:

files:
    type: files

I would assume, files uploaded here use the defaultfile blueprint. However, when I upload a file, the default blueprint is not assigned, but partially used, and partially ignored.

Given this /site/blueprints/files/default.yml blueprint:

title:
  *: file
options:
  changeTemplate: true
fields:
  info:
    type: info
    label:
      *: info
    text: Test
    theme: none

The uploaded file looks like this in the panel:

I’ve highlighted three things in the image with numbered labels to illustrate my problem:

  1. The template (“Vorlage”) is empty, as the blueprint was not assigned to this file.
  2. The change template (“Vorlage ändern”) is disabled, despite that being explicitly enabled. Yes, there are other blueprints available that are compatible.
  3. The Info field from the blueprint is shown, proving Kirby is using the default files blueprint.

I must be doing something wrong, but I cannot figure it out. For completeness, here is the /site/blueprints/files/image.yml file:

title:
  de: Bild
  en: Image
accept:
  type: image
options:
  changeTemplate: true
fields:
  alt: fields/alt

Some tinkering to gather more info:

If I open the file’s sidecar .txt file and edit it to use the image blueprint, I get this:

The annotations this time show:

  1. The blueprint “Image” is being used. However, it’s not processed correctly. The blueprint has an English and a German title, but Kirby acts as if there was only an English title.
  2. I can now change the template (see below)
  3. The default blueprint’s “Info” has been replaced by the “image” blueprint’s Alt-text field, proving Kirby is using the blueprint.

When I click on change template, I get a dialog that uses the provided translations for the Image blueprint, and ignores the title provided in the Default blueprint:

Changing to the default template, shown here to have the name “-” (dash), brings me back to the state I was in before editing the sidecar file (see first image).

Help, I’m lost…!

I should probably clarify my goals:

I want files without a specific blueprint to fallback to the default and I want to be able to change the template/blueprint in the panel.

In the parent page, is there any files section or files field that accepts the image file blueprint? Kirby will only allow switching the file template if the parent actually allows one.

There is the one files-field that has no restrictions at all, as mentioned, yes. There are no other files fields in the parent page.

What Kirby version are you using (to be sure to look in the right spots)?

I’m currently on:

{
  "info": {
    "kirby": "4.7.0",
    "php": "8.4.4",
    "server": "PHP/8.4.4 (Development Server)",
    "license": "Unregistriert",
    "languages": [
      "de"
    ]
  },
  "security": [
    "Die Seite läuft lokal mit abgeschwächten Sicherheitschecks",
    "Debugging muss im öffentlichen Betrieb ausgeschaltet sein",
    "Der Vue Template Compiler ist aktiviert"
  ],
  "plugins": [
    {
      "name": "bnomei/feed",
      "version": "5.0.2"
    },
    {
      "name": "stairjoke/custom-markdown",
      "version": "?"
    }
  ]
}

It’s running via Kirby’s built-in router on localhost using @php -S localhost:8000 kirby/router.php. The stairjoke/custom-markdown plugin is from me, it replaces the markdown renderer with Michelf\MarkdownExtra and modifies the output. Shouldn’t have any impact on uploading files.

You need to assign the template via the uploads option

Thank you @texnixe! Does this also apply for the default file blueprint? When I manually assign it, Kirby behaves differently from when a file has no file blueprint assigned:

Here is the sidecar file as Kirby creates. This configuration produces the result shown in the first screenshot above.

rexie-a-very-expressive-cat-v0-n2xk788euufe1.jpg.webp.de.txt

Sort: 1

----

Uuid: kYiGMIDKOFkTqvVx

Here is the sidecar file manually adjusted to use the default blueprint:

rexie-a-very-expressive-cat-v0-n2xk788euufe1.jpg.webp.de.txt

Sort: 1

----

Template: Default

----

Uuid: kYiGMIDKOFkTqvVx

This produces the following result:

The annotations this time show:

  1. The blueprint “Default” is being used, and processed more completely than before, but not perfectly. The title from default.yml is still ignored.
  2. The dropdown menu now allows changing the template (“Vorlage ändern”).
  3. The Info section from the default blueprint is shown the same as when no blueprint is assigned.

The change template dialog looks like this now:

It now offers to remove the default file blueprint, it does not offer to apply the Image blueprint.

Two questions:

  1. From my understanding, considering the parent field in the page to which this file belongs has no restrictions, it should allow me to set the Image blueprint. Why doesn’t it?
  2. The change template dialog should not allow me to remove the default blueprint, as this is the blueprint to be used when none other applies. The default should be the default, or is the default “null”, and the default is not actually Kirby’s default? I’m confused.

Amending my last reply and question:

Is there any way to have a files-section that allows uploading all kinds of allowed file-types, as in a field that does not specify any one template to be used, while allowing users to change the template/file blueprint on a file-by-file basis?

I also tried adding multiple templates to the files-field like so:

files:
  type: files
  uploads:
    template:
      - default
      - image

And like so:

files:
  type: files
  uploads:
    template: default, image

However, this made no difference, the result is still that neither the “Default”, nor the “Image” blueprint are applied when uploading a file. I also cannot change the template for the file, when trying either of these approaches.

my 2c yaml encoding?

check mixed spaces and tabs for indents. only use one of them in a single file. consider using a editor that highlights these. optionally try my schema to detect issues in the blueprint syntax albeit kirby is generally very forgiving here.

You can only assign one type of template here

I installed the schema, thanks @bnomei, that’s neat! It seems, though, it can’t handle the * wildcards, as in

title:
  *: file

The * is considered an error (see screenshot below). That might just be my editor (Nova by Panic). I also checked, and all my YAML files only use spaces for indentation, no tabs.


@texnixe after trying to add multiple, I suspected. Thanks for confirming.

The question remains: How can I allow a user to pick a template for a file they uploaded? I thought adding the changeTemplate: true-option would do it, but as shown above, it’s not working. It should at least allow “Default” and “Image” for image files, I thought, but it’s not allowing anything.

For example, in the Plainkit, the default page blueprint has a files-section. When a user uploads a file using this section, no template will be applied. Clicking on the uploaded file, will open the file’s detail-page. On this page, shouldn’t

  1. The default blueprint be applied?
  2. The option to change the template be enabled and show all available and compatible file blueprints?

When I simply add a “default” and an “image” blueprint to the Plainkit, this doesn’t work.

Changing the template requires that you have another field or section that has that template assigned. A workaround would actually be a select field called template with possible templtes that you want to allow. But make sure you have a section with no templte assigned in that case.

Thanks, this solved it. Unfortunately, this method means users have to click save after changing the type, before seeing the desired blueprint applied to their file.

I solved it with a custom plugin using the hook “file.create:after”, but I’d love to see Kirby gain more smarts about files.