Fancybox and CMS / how to remove "image not found"

I am working on a project and have added fancybox to a template page:

ex:
https://fred-kleinberg.webflow.io/peintures/we-can-be-heroes
https://fred-kleinberg.webflow.io/peintures/odyssee

I was able to customize fancybox as wanted and it is all working fine.

The issue that I am facing is that Fancybox is “registering” the fields that have no content and listed them in fancybox under “no image found”

Have tried the easy way by adding conditions (ex: image 1 / is set) but that have no impact.

The various JS options suggested by chatGPT have not done the trick either.

Is there any humban ;-) that could solve this issue ? Thank you in advance


Here is my site Read-Only:

(Webflow - Fred Kleinberg)

Hi Gael,

It took some debugging but i found a solution for your problem. You can add a little bit of custom CSS to your page settings, this will hide the fancybox images which don’t have an image.

<style>.fancybox__slide.has-error { display:none!important; }</script>

See attached screenshot

Goodluck!

Kind regards,
Edwin

2 Likes

@edwine1987 Thank you so much. This is really good.

Ideally, I would like the now “empty” slides (without the “image not found” message) not to appear. This would mean that you would navigate from the last image to the first one.

How would you go about this ?

Hi Gael,

Can you send me a screenshot?

@edwine1987 Here you go:

Each collection can hold up to 27 images.
This means that if I only had 10 images, I have 17 more empty slides.

Ex: Fred Kleinberg

Ah, okay, i will check it out in a couple of hours.

Hi Gael,

That won’t be possible with CSS, we need some JavaScript for this, first we need to remove all the elements that have no image, after that you can call the Fancybox.bind function

Place the following JavaScript just above Fancybox.bind…

function removeInvisibleElements() {
    const elements = document.querySelectorAll('.w-condition-invisible');
    elements.forEach(element => element.remove());
}

removeInvisibleElements();

Marked with the redline:

Goodluck!

Kind regards,
Edwin

@edwine1987
I am super impressed. This works like magic
Thank you a million

1 Like

@Gato good to hear that!