length of a gallery

Hello,
I have a website with a gallery (connect to a dataset) and I would like to hide gallery when it’s empty but when I use Corvid to count items, it doesn’t work. I have no console error but always return 0 even if the gallery is not empty. Could you help me please ?

$w.onReady(function () {
    console.log($w("#gallery1").items.length);
});

Just do something simple like this.

  
$w.onReady(() => {
$w("#myDataset").onReady(() => {
// Gets the current item properties and stores them in a variable called item
const item = $w("#myDataset").getCurrentItem();
// Checks if the current item has a value in the "picture" field
if (!item.picture) {
// Collapses the gallery if there is no value for "picture"
$w("#gallery").collapse();
}
});
});

It’s work perfectly ! Thanks a lot

I have just again a problem with collapse which doesn’t work of some galleries ? Are there something to configure to collapse them correctly ?

Here, you can see my problem between kitchen and bedromm galleries, the gallery between them is collapsed but there are a blank space.

https://lescreatifsanonymes.wixsite.com/website-2/properties/Docks-5

Thanks

When a element is collapsed, it is collapsed and doesn’t take up any room on your page.
https://support.wix.com/en/article/corvid-how-page-layout-is-affected-when-elements-change-size

https://www.wix.com/corvid/reference/$w.CollapsedMixin.html
A collapsed element, unlike a hidden element, does not take up any space on the page. When collapsed, elements positioned within 70 pixels below the collapsed element and each other move up to take the collapsed element’s place where possible. The elements that move up maintain their positions relative to one another.

@givemeawhisky Thanks for explaination, now I understand why I had a big space between my 2 galleries. I fixed this by reducing space less than 70 pixels and my gallery correctly collapsed now but I still have a space and I don’t know why. Is it a default margin between block after collapse ? Is it possible to delete it? Thanks !