I have connected a repeater to a content collection titled “news”. These are two different repeaters on desktop and mobile as I have a different design for mobile view.
I have 3 image columns in my content collection to have up to 3 images for each news entry (as i cannot add a gallery in the repeater)
I want the images to only show if the column is populated in the content manager.
This is the code that I added in for the mobile repeater:
$w ( “#repeater8” ). onItemReady (( $item , itemData ) => {
if ( itemData . image3 !== undefined && itemData . image3 !== null ) {
$item ( “#imageX308” ). src = itemData . image3 ;
} else {
$item ( “#imageX308” ). collapse ();
}
});
$w ( "#repeater8" ). onItemReady (( $item , itemData ) => {
if ( itemData . image2 !== **undefined** && itemData . image2 !== **null** ) {
$item ( "#imageX309" ). src = itemData . image2 ;
} **else** {
$item ( "#imageX309" ). collapse ();
}
})
And this has seemed to work:
I have done the exact same code but changed it to link with the images and repeater that appears in desktop view:
$w ( “#repeater8” ). onItemReady (( $item , itemData ) => {
if ( itemData . image3 !== undefined && itemData . image3 !== null ) {
$item ( “#imageX300” ). src = itemData . image3 ;
} else {
$item ( “#imageX300” ). collapse ();
}
});
$w ( "#repeater2" ). onItemReady (( $item , itemData ) => {
if ( itemData . image2 !== **undefined** && itemData . image2 !== **null** ) {
$item ( "#imageX292" ). src = itemData . image2 ;
} **else** {
$item ( "#imageX292" ). collapse ();
}
})
})
However, it does not collapse the images and instead leave a big gap as highlighted here in yellow:
Can anyone please provide some assistance as to where I have gone wrong here?
Thanks!