Retrieving page files sorted

Hi there,

I’m displaying my page’s files on the template, so I’d like to display them sorted as on the panel. Since I didn’t find any method that could get me the list sorted, I did it right on the template, like this:

<?php 
$files = $page->files()->toArray();

usort($files, function($a, $b){
    if ($a->sort() == $b->sort()) {
        return 0;
    }

    return ($a->sort() < $b->sort()) ? -1 : 1;
});
?>

It works, but it doesn’t seem right to do this on the template, or even create a controller just for that. Is there any built-in way of doing that?

Take a look here: http://getkirby.com/docs/cheatsheet/files/sortBy

1 Like

Great, totally missed that.

Thanks :slight_smile: