Filter images by suffix

Hi,
how can I filter images through an suffix like _thumb?
I tried foreach($page->images()->not('_thumb.jpg') as $image): for displaying only the fullsize images.
But it shows all images also the thumbs.

Cheers

http://forum.getkirby.com/t/filter-to-exclude-files-that-contain-specific-string-in-their-name/573/4?u=texnixe

1 Like

Given an array of files, like $page->images(), you can do something like:

$images = $page->images();
$without_thumbnails = $images->filter(function($image) {
  # Note that the !== or === operators are required for
  # matching, here, because 0 and false mean different
  # things as return values from strpos:
  return strpos($image->filename(), '_thumb') !== false;
});

Mind you, there is a built-in thumbnail generation method!

@texnixe, via Bastian— nailed it! Good idea to use static str class methods. Much easier to read than PHP’s myriad string functions. :smile:

1 Like

Hi,
thankyou for you help!
But so much crazy filter functions. I can remember that in Kirby 1 it was so simple with
->not().
In the archiv forum I had an thread about the same problem, but i have to see that the search function was removed. This is not so pretty!
Yes of course I know the thumbnailfunction but i don’t want to use it because I have different cropped images.

Cheers

As far as I know, not() only works with specific filenames or an array of file names, not with a wildcard.

Yeah, the search function is missing from the old forum, that’s why I downloaded the stuff and use local search;) works much better (or use google search)

Ah okay good to know.

That sounds like a good idea :slight_smile: