# Each page blueprint must have a title, the title may be different from the file name
title: Verhaal
# 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 verhaal is still in draft mode. It can only be seen by editors with panel access.
unlisted:
label: In Review
text: The verhaal 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 verhaal 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:
description:
label: Card description
type: text
subheading:
label: Intro
type: textarea
buttons: false
size: medium
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: false
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
Then the reason why the example does not work is that there is a Page model note.php, which already converts the cover field to file and if it doesn’t exist falls back to the first image in the page.
So calling toFile() on $page->cover() will not work and it should be only
<?php if ($cover = $page->cover()): ?>
Or you need to remove the cover() method from the model.
# Each page blueprint must have a title, the title may be different from the file name
title: Verhaal
# 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 verhaal is still in draft mode. It can only be seen by editors with panel access.
unlisted:
label: In Review
text: The verhaal 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 verhaal 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:
description:
label: Card description
type: text
subheading:
label: Intro
type: textarea
buttons: false
size: medium
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: false
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
<?php
/**
* Page models extend Kirby's default page object.
*
* In page models you can define methods that are then available
* everywhere in Kirby where you call a page of the extended type.
*
* In this example, we define the cover method that either returns
* an image selected in the cover field or the first image in the folder.
*
* You can see the method in use in the `note.php` snippet.
* and in the `site/blueprints/sections/notes.yml` image query
*
* We also define a custom date handler here, which keeps date formatting
* for the published date consistent in templates, snippets and blueprints.
*
* More about models: https://getkirby.com/docs/guide/templates/page-models
*/
class NotePage extends Page
{
public function cover()
{
return $this->content()->cover()->toFile() ?? $this->image();
}
public function published($format = null)
{
return parent::date()->toDate($format ?? 'd M, Y');
}
}