Hiding empty sections in a database gallery

Though it has been awhile, I’d still like to share how I solved this issue with this community.
Here’s the code.



// Gallery:

let image1 = $w(“#dynamicDataset”).getCurrentItem().image001;
let image2 = $w(“#dynamicDataset”).getCurrentItem().image002;
let image3 = $w(“#dynamicDataset”).getCurrentItem().image003;
let image4 = $w(“#dynamicDataset”).getCurrentItem().image004;
let image5 = $w(“#dynamicDataset”).getCurrentItem().image005;
let image6 = $w(“#dynamicDataset”).getCurrentItem().image006;
let image7 = $w(“#dynamicDataset”).getCurrentItem().lifestyleImage;

let refID = $w(“#dynamicDataset”).getCurrentItem().title;

if (refID === “TITLE C”){
$w(“#gallery”).items = [ { src: image1, },{ src: image2, },{ src: image3, },{ src: image4, }];
}
else if (refID === “TITLE D”){
$w(“#gallery”).items = [ { src: image1, },{ src: image2, },{ src: image3, },{ src: image4, },{ src: image5, }];
}
else {
$w(“#gallery”).items = [ { src: image1, },{ src: image2, },{ src: image3, },{ src: image4, },{ src: image5, },
{ src: image6, }];
}

})


Since most of my products have the same amount of the images. So I just add other condition for products that have different amount. It works pretty well so far.

Any suggestion will still be appreciated!
Thanks!