I have an implicitly sortable files section in my blueprint
The ‘imagen’ template:
label: Texto alternativo
label: Pie de foto
I access this files section in my template as such:
<?php foreach ( $page->images() as $img ): ?>
<?php endforeach ?>
But the order of images in the panel and in the html output does not match, see:
I would bet the order they show in is the order in which they were uploaded but did not fully test this
Is this the expected behaviour?
I cannot see where may I be affecting the sorting of these images, nor any mention in the reference about this being a default behaviour.
Some light please
By default the images are sorted by filename. To have them come out on the front end template in the sort order set by the field, you need to sort them that way on the front end.
$images = $page->images()->sortBy('sort', 'asc');
I see, thank you @jimbobrjames.
Is this perhaps specified somewhere in the reference? Because I could not find it, for example in $page->images() or $page->files() or in their respective source codes.
It’s in the sorting cookbook guide…
But there it does not say that default is filename sorting, does it ?
Actually it would lead me to believe that to achieve filename sorting I have to do:
// sort by filename
$files = $page->files()->sortBy('filename');
Well no, it doesnt specifically mention the default. However, Kirby generally defaults to alpha sorting on titles or filenames whenever you work with a group of something, unless you tell it otherwise.
Good to know. I’ve opened an issue anyway for consideration https://github.com/getkirby/getkirby.com/issues/846