Understand file and image.yml

Hi,

From the starter kit, I change the note.yml to add an image — I would like to have a « model » for image to add caption, alt and more like image.yml
The first way I add image in sections works but with the second way I have this message when I click on picture This page has no blueprint setup yet (with my picture in the top of the page).
What’s wrong ?

num: date
icon: 📖

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
    

      ## The `images` files section shows all images of the current page that use the `image` template
    sections: 
      image:
        template: image #work
        type: files
        info: "{{ file.dimensions }}"
        layout: cards
        multiple: false
        max: 1
      supersection: # the name of the section
        type: fields # the type of the section
        fields:
          texte:
            type: textarea
            size: large
          image:
            template: image #not OK <---- ? 
            type: files
            layout: cards
   
  - 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

The first files thingy is a files section. It does have a template option.

The second example is a files field. A files field does not have a template option. However, you can set the template for files you upload through this field via the upload option:

image:
  type: files
  layout: cards
  upload:
     template: image

In case you have other file types in your page and you want to limit what files can be selected, you can use the query option:

image:
  type: files
  layout: cards
  query: page.images.filterBy('template', 'image')
  upload:
     template: image

Note that if you call your field image you run into conflicts with Kirby’s native image() method. If you want to call this field in your template, you would have to call it like this:

$image = $page->content()->image()->toFiles();

Therefore, consider renaming or prefixing the fieldname.

1 Like