this code is being used on a dynamic item page which connects to the “important documents” cms collection.
this is my current code. the “ImportantDocuments” is my cms collection and the item.gallery is a boolean value to hide the #gallery1 piece on my page.
//*****USER-INTERFACE*****
const dynDataset = 'ImportantDocuments'; // <-- ID of your DYNAMIC-DATASET here.
const myGallary = 'gallery1'; // <-- ID of your GALLERY here.
//*****USER-INTERFACE*****
$w.onReady(() => {console.log('...page is ready...');
// Wait for the dataset to load the current item
$w(`#${dynDataset}`).onReady(() => {console.log('...dyn-dataset is ready...');
const curItem = $w("#ImportantDocuments").getCurrentItem(); console.log('Current-Item: ', curItem);
// Check the boolean field 'gallery'
if (!curItem.gallery) {$w(`#${myGallary}`).collapse();} // Hide the gallery if false
else {$w(`#${myGallary}`).expand();} // Show the gallery if true (optional)
});
});
// Make sure your GALLERY-FIELD inside of your collection is a --> BOOLEAN-FIELD.
Clear code-version:
const dynDataset = 'ImportantDocuments';
const myGallary = 'gallery1';
$w.onReady(() => {
$w(`#${dynDataset}`).onReady(() => {
const curItem = $w("#ImportantDocuments").getCurrentItem();
if (!curItem.gallery) {$w(`#${myGallary}`).collapse();}
else {$w(`#${myGallary}`).expand();}
});
});
// Make sure your GALLERY-FIELD inside of your collection is a --> BOOLEAN-FIELD.
Try this to make it maybe even more stable…
if (!Boolean(curItem.gallery)) {
$w(`#${myGallary}`).collapse();
} else {$w(`#${myGallary}`).expand();}
Thank’s!
Normaly i should have resolved it withing minutes, but this long way to solution was the result of not using the DATASET (especially the dynamic one) for decades → you know, i like to generate everything by code → Wix-Data is what i like