I am building a website for a client as a one-pager.
All images will be uploaded as $site elements, so they are easily available everywhere on the website.
The website consist of different sections one of them is called ‘projects’.
I would love to be able to show images in those sections based on a name partial.
For example all images for ‘projects’ are supposed to be named like this:
project-1.jpg
project-2.png
project-3.gif
etc
With this pattern I should be able to get all images with ‘project’ as a partial.
File extensions are only examples, but I basically need to support those three types.
I understand, that I can get all images for $site by doing the following:
That’s because findBy() only takes two parameters, $key and $value, no filter operators.
However, for your use case, you do not need the filter operator, if the filename is. always the same:
$image = $page->images()->findBy('name', 'icon');
should do. the job, because name()compares the filename without the extension, while filename()looks for name with extension. You can, however, find all that in the docs.