If a item hasn't image not load/show in the dynamic gallery

Hi i currently used the code for dynamic gallery (on my dynamic item page). the code working partially and i have problem about this.

$w.onReady(function imatDataset_onReady() {
let item =$w(’ #imatDataset ‘).getCurrentItem(); $w(’ #imatgallery ').items = [
{src: item.s1},
{src: item.s2},
{src: item.s3},
];
});

for example - >> i want to display in the gallery max. 3 images for each item but not Necessarily/Always 3. So is there a solution for this?

because In some case item has only 2 or 1 image. but when in the database are lass images than 3 for any item > gallery shows blank (empty) images boxes — and message in console on preview → " Wix code SDK Warning: The src parameter of item at index 1 that is passed to the items method cannot be set to null or undefined." (see screen) ________ thanks for all in advance ________


thanks

Hey,

I suggest checking each image src if it exists before adding it to the items array.
You can try something like the following:

const items = [];
if (item.s1) {
    items.push({src: item.s1});
}
if (item.s2) {
    items.push({src: item.s2});
}
if (item.s3) {
    items.push({src: item.s3});
}
$w('#imatgallery').items = items

This way, if an image does not exist it won’t be added to the items array.

Good Luck,
Itai

Hi, can you write the complete example code, please!

i have the same problem, if somebody now about that, please tell me.
Thanks!

Took some digging, but I found my old answer to the same question (inc code): https://www.wix.com/code/home/forum/community-discussion/database-and-dynamic-product-page

Thanks Giri, i could do this!

Thanks again