How to sort pictures by name

I have build a little gallery template with :

{% for image in page.media.images %}
{{ image.cropResize(100000,350).html }}
{% endfor %}

But I want to sort pictures by name … How can I do that ?

The images should be by default sorted by filename. The page.media.images object is an array of medium objects where the key is the filename so you could try resorting with page.media.images|sort but it should not be necessary.

Thanks “|sort” is really necessary to get the file in the right order. without |sort they are sorted by date.

same for me when is on the server, might be related with php / apache config …
also had to add sort to get the first image right

…media.images|sort|first

What were the filenames you had in your folder, and what order were they displaying in?

01.livro-grafites-brasil.jpg
02…livro-grafites-brasil.jpg
03.livro-grafites-brasil.jpg
04.livro-grafites-brasil.jpg
05.livro-grafites-brasil.jpg
06.livro-grafites-brasil.jpg

Could not find any logic on the order. 05 was showing first …
But this was fixed with the sort filter.

Yep I think my files too were by date …

Ok thanks, i’ll look into it.

Kind of strange, I am unable to replicate using those filenames. Grav is just ordering by looping over the files with a PHP DirectoryIterator. I’ve manually sorted using a natural algorithm before returning the array of images now, so in future releases |sort should not be necessary.

Out of curiosity, do you guys also have issues with regular Grav pages not being in the expected order? Even when you use .01, .02, .03 prefixes?

yes , I also had it with pages, and to tell the true I also had this kind of issue sometime ago with pico CMS, but I must remind that the problem only shows off when uploaded to the remote server ( my runs with PHP 5.4.33 ) on my MAMP all looks fine.

Do you happen to know what kind of server you are running on your remote site (OS version, perhaps hosting provider name, PHP version, etc)?

I think I can probably force a sort to override the directory iterator for pages too, but it would be really nice if I could recreate it to ensure it’s actually working.

I am also on siteground with with PHP 5.4.33 , forcing sort for pages did worked too

Could you send me a zip of your user folder containing folders that have this issue with ordering on SiteGround? Or put them on dropbox? Please send them to rhuk(a)getgrav.org

I am having this issue, works on my local machine but not not when I move the site to production. My question is , how do I force sort taxonomies to list by alpha? I am not using the taxonomy list plugin.

Most likely if it works local and not remotely, then it’s a case-sensitivity thing… This is because by default, Windows and OS X (most common user OSes) are not case-sensitive, and most servers run Linux which is.

Can you be more specific? Is it the way I am I am naming my directories that contain the md file? They are all first word capitialized. Should I change to all lowercase? It was working before and it broke recently when we incorporated a category in the taxonomy. Thanks.

Can you delete the reply above? This is properly formatted.

My mac is not case sensitive. Do you have any other ideas? I did notice that alpha sort works one level down in the directory structure, but break at two levels down. Could this be caused by a conflict with a plugin?

   Type (Bundle):            hfs
   Name (User Visible):      Mac OS Extended (Journaled)
   Journal:                  Journal size 40960 KB at offset 0x11bec000
   Owners:                   Enabled```

You are saying that the sorting is working locally, but not on your remote server. So that leads me to think that it’s a case sensitivity issue somehow. I would need to see the code you are using to sort your pages, along with a screenshot of the files themselves to know if that’s the case.

Alternatively you can zip up your site, and make it available for me to download and test it myself (my mac is formatted with case sensitive file system for just this reason). if you go with this approach, please let me know exactly which page is having the problem.

that sounds great. how do I get a zip file to you?
thanks!

It might be better to clone our github repo since the problem is there, my local is working.