Exclude from image list selected field

Hi, sorry i get stuck on the weirdest parts lol.
Ive tried this:

<?php foreach($page->images()->filterBy('filename', '!=', $page->image($page->artista())->url()) as $image): ?>

Basicly i need to list all images on the page except the image selected on the panel that i named “artista”.

Thanks in advance

You are trying to get the url of a collection instead of a single image here, which will not work.

foreach($page->images()->filterBy('filename', '!=', $page->image($page->artista()->value())) as $image): ?>

You could also use not()

<?php foreach($page->images()->not($page->image($page->artista()->value())) as $image): ?>

Ive tried both and the image is still listed, could it be something with the rest of the code?
Here’s the full foreach:

<?php foreach($page->images()->filterBy('filename', '!=', $page->image($page->artista()->value())) as $image): ?>
<?php endforeach ?>

Oh, I see the problem, try:

 <?php foreach($page->images()->filterBy('filename', '!=', $page->cover()) as $image): ?>


 <?php foreach($page->images()->not($page->cover()->toString()) as $image): ?>

This bit:


does not give you the filename, but the file path, so the condition is never true.


That worked, thanks!
Really helpful as always.

Thank you so much! This is some crucial tip here.

I feel this should be mentioned right alongside the panel field Image. I think this might be a commonly needed thing.


1 Like