Fatal Error on gallery overview page

Hi,

I’m just learning Kirby as I’m taking over the management of our youth alpine club website.
We have a page which displays an overview of all photo albums of the past trips. Unfortunately it throws the following error:

Fatal error: Uncaught Exception: Invalid grouping value for key: bilder-und-berichte/area-47 in /var/www/virtual/.../htdocs/kirby/core/pages.php:259 Stack trace:
#0 /var/www/virtual/.../htdocs/site/templates/berichte.php(7): PagesAbstract->groupBy('year')

What is area-47? To my knowledge there exists no folder or file with this name.

Line 7 is

$years = $page->children()->visible()->sortBy('year', 'DESC')->groupBy('year');

Could anyone help me to get a grip of what’s going wrong there?

mshoestrng

The groupBy() method only works if the year field in each of the pages does actually contain a value.

So you have several options:

  • Either filter your pages, so that the collection you want to group only contains children with a year value
  • Or make sure that all the children have a filled in year value (e.g. require the field and set a default)
  • If you don’t want to edit all children and still want to use some default value, you could map a value to the year field in case it is empty

Code for first option:

$years = $page->children()->visible()->filter(function($child) {
  return $child->year()->isNotEmpty();
})->sortBy('year', 'DESC');
$years = $years->groupBy('year');

area-47 seems to be a child page of bilder-und-berichte

Code for third option:

$years = $page->children()->visible()->map(function($child) {
  if($child->year()->isEmpty()) {
    $child->year = '2018'; // or whatever
  }
  return $child;
})->sortBy('year', 'DESC')->groupBy('year')

There was indeed a folder called “49-area-47” which I hadn’t noticed. Funny enough the error went away after re-syncing. Thanks!