Hi,
I write this :
$page->images()->filterBy('template', 'image')->sortBy('sort');
But if there is no reorder (no drag), sort is empty and order is not as expected (based on filename).
I miss something ?
Hi,
I write this :
$page->images()->filterBy('template', 'image')->sortBy('sort');
But if there is no reorder (no drag), sort is empty and order is not as expected (based on filename).
I miss something ?
<?php foreach ( $page->images()->filterBy('template', 'image')->sortBy(function($file) {
if ($file->sort()->isNotEmpty()) {
return $file->sort();
}
return $file->filename();
}) as $file) {
echo $file->sort() . '-' . $file->name();
}
Will sort them by sort first, then by filename
This topic contains a short solution:
$page->images()->filterBy('template', 'image')->sortBy('sort','asc', 'filename', 'asc');
Kirbyly Perfect !