# Dynamic page get boolean value from cms and display hide item if false

**URL:** <https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221>\
**Category:** Ask the community\
**Tags:** code, cms, wix, wix-studio\
**Created:** [October 13, 2025, 6:14pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221 "2025-10-13T18:14:34Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![infernalviper11](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/infernalviper11/32/111639_2.png) [@infernalviper11](https://forum.wixstudio.com/u/infernalviper11)\
**Post date:** [October 13, 2025, 6:14pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/1 "2025-10-13T18:14:34Z")

</div>

**I’m having trouble with**  
Using a boolean value in a cms collection to change if an item is displayed or not.

**Working in**  
Wix Editor, Dev Mode, and CMS

**What I’ve tried so far**  
I’ve followed this tutorial with a similar solution but it won’t work for me.  
[https://forum.wixstudio.com/t/solved-show-or-hide-element-in-dynamic-page-depending-on-boolean/25204/2](https://forum.wixstudio.com/t/solved-show-or-hide-element-in-dynamic-page-depending-on-boolean/25204/2)

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.

$w.onReady(() =\> {

```
$w("#ImportantDocuments").onReady(() => {

```

**const** item = $w(“#ImportantDocuments”).getCurrentItem();

**if** (!item.gallery) {

```
        $w("#gallery1").collapse();

    }

});

```

});

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 13, 2025, 6:51pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/2 "2025-10-13T18:51:46Z")

</div>

```javascript

// *****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:**

```javascript

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…

```javascript
if (!Boolean(curItem.gallery)) {
    $w(`#${myGallary}`).collapse();
} else {$w(`#${myGallary}`).expand();}

```

---

<div class="post-metadata">

**Author:** ![infernalviper11](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/infernalviper11/32/111639_2.png) [@infernalviper11](https://forum.wixstudio.com/u/infernalviper11)\
**Post date:** [October 13, 2025, 8:06pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/3 "2025-10-13T20:06:03Z")

</div>

![Screenshot 2025-10-13 at 1.04.53 PM](https://us1.discourse-cdn.com/wix/original/3X/0/c/0c26f65e9e3f511f0c52a2343f3d4204095d0080.jpeg)

seeing this error. not sure why. its literally on the page connected to the collection

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 13, 2025, 8:19pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/4 "2025-10-13T20:19:52Z")

</div>

…then try it like …

```javascript
const dynDataset = '#ImportantDocuments'; 
const myGallery = '#gallery1'; 

$w.onReady(() => {
    $w(dynDataset).onReady(() => {
        const currentItem = $w(dynDataset).getCurrentItem();
        const galleryField = currentItem.gallery;

        if (!galleryField || galleryField.length === 0) {
            $w(myGallery).collapse();
        } else {
            $w(myGallery).expand();
        }
    });
});

```

By the way → **ImportantDocuments** ← this is your → **COLLECTION- ID** , not so ?  
It is not the dataset-ID, right?

Did you mixed up **COLLECTION-ID** and **DATASET-ID**?

**Try also to change from …**  
const dynDataset = ‘#ImportantDocuments’;  
const myGallery = ‘#gallery1’;

**…to…**  
**let** dynDataset = ‘#ImportantDocuments’;  
**let** myGallery = ‘#gallery1’;

---

<div class="post-metadata">

**Author:** ![infernalviper11](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/infernalviper11/32/111639_2.png) [@infernalviper11](https://forum.wixstudio.com/u/infernalviper11)\
**Post date:** [October 13, 2025, 8:54pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/5 "2025-10-13T20:54:52Z")

</div>

I believe I was using the collection ID. I will try this fix. thank you

---

<div class="post-metadata">

**Author:** ![infernalviper11](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/infernalviper11/32/111639_2.png) [@infernalviper11](https://forum.wixstudio.com/u/infernalviper11)\
**Post date:** [October 13, 2025, 9:06pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/6 "2025-10-13T21:06:28Z")

</div>

![Screenshot 2025-10-13 at 2.05.29 PM](https://us1.discourse-cdn.com/wix/original/3X/5/7/57aaafbade62bf35926cf8fdc12fc56b54409209.png)

 ![Screenshot 2025-10-13 at 2.05.42 PM](https://us1.discourse-cdn.com/wix/original/3X/4/1/4108b8ebbf555e1f6281a5d9a3084e0432a2dd05.png)

I adjusted the code to the values. it at very least compiles.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 13, 2025, 9:09pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/7 "2025-10-13T21:09:33Z")

</div>

I did a mistake.

Since you are using a dynamic dataset, normaly it should be like…

```javascript
let dynDataset = '#dynamicDataset'; 
let myGallary = '#gallery1'; 

$w.onReady(() => {console.log('...page is ready...');
    $w(dynDataset).onReady(() => {console.log('...dynamic dataset is ready...');
        const curItem = $w(dynDataset).getCurrentItem(); console.log('Current-Item: ', curItem);
		if (!curItem.gallery) {$w(myGallary).collapse();}
        else {$w(myGallary).expand();}
    });
});

```

**…or you do use → ‘#dynamicDataset’ ← in standard mode…**

```javascript
let myGallary = '#gallery1'; 

$w.onReady(() => {console.log('...page is ready...');
    $w('#dynamicDataset').onReady(() => {console.log('...dynamic dataset is ready...');
        const curItem = $w('#dynamicDataset').getCurrentItem(); console.log('Current-Item: ', curItem);
		if (!curItem.gallery) {$w(myGallary).collapse();}
        else {$w(myGallary).expand();}
    });
});

```

# **EDIT:**

**Ok, i tested this one on my own end and it worked without issues…**

```javascript
let dynDataset = 'dynamicDataset'; 
let myGallary = 'gallery1';

$w.onReady(()=> {console.log('...page is ready...');
    $w(`#${dynDataset}`).onReady(() => {console.log('...dynamic dataset is ready...');
	    const curItem = $w(`#${dynDataset}`).getCurrentItem(); console.log('Current-Item: ', curItem);
		if (!curItem.gallery) {$w(`#${myGallary}`).collapse();}
        else {$w(`#${myGallary}`).expand();}
    });
});

```

**Important checkpoints:**

- using → let ← instead of const will prevent from errors.
- using → dynamicDataset ← when working on a dynamic dataset → $w(‘#dynamicDataset’)
- paying attention on how exactly you do your definitions…  
a) **either like…**

```javascript
      const dynDataset = '#dynamicDataset'; 
      const myGallary = '#gallery1';

```

```
    b) ...or like...

```

```javascript
      const dynDataset = 'dynamicDataset'; 
      const myGallary = 'gallery1';

```

```
    c) ...or like...

```

```javascript
      let dynDataset = '#dynamicDataset'; 
      let myGallary = '#gallery1';

```

```
    d) ... or like ...

```

```javascript
      let dynDataset = 'dynamicDataset'; 
      let myGallary = 'gallery1';

```

**… so also reacting accordingly…**  
1) …either like —\> $w(dynDataset)

![2025-10-13 23_44_36-Dynamic page get boolean value from cms and display hide item if false - Ask the](https://us1.discourse-cdn.com/wix/original/3X/1/4/1456a6a5026522f654d814c08998cf099868bfd3.png)

## **…or you do it even better → directly \<— like …**

```javascript
let dynDataset = $w('#dynamicDataset'); 
let myGallary = $w('#gallary1');

$w.onReady(()=> {console.log('...page is ready...');
    dynDataset.onReady(() => {console.log('...dynamic dataset is ready...');
	    const curItem = dynDataset.getCurrentItem(); console.log('Current-Item: ', curItem);
		if (!curItem.gallery) {myGallary.collapse();}
        else {myGallary.expand();}
    });
});

```

---

<div class="post-metadata">

**Author:** ![infernalviper11](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/infernalviper11/32/111639_2.png) [@infernalviper11](https://forum.wixstudio.com/u/infernalviper11)\
**Post date:** [October 13, 2025, 10:41pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/8 "2025-10-13T22:41:03Z")

</div>

> [@CODE-NINJA](#):
>
> ```javascript
> let dynDataset = 'dynamicDataset'; 
> let myGallary = 'gallery1';
> 
> $w.onReady(()=> {console.log('...page is ready...');
> $w(`#${dynDataset}`).onReady(() => {console.log('...dynamic dataset is ready...');
> const curItem = $w(`#${dynDataset}`).getCurrentItem(); console.log('Current-Item: ', curItem);
> if (!curItem.gallery) {$w(`#${myGallary}`).collapse();}
> else {$w(`#${myGallary}`).expand();}
> });
> });
> 
> ```

that worked! its functioning now!!! thanks so much!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 14, 2025, 6:27pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/9 "2025-10-14T18:27:27Z")

</div>

No problem you are welcome. 😉  
 ![bcabb205-05fd-443e-ad70-6244b69b6194](https://us1.discourse-cdn.com/wix/original/3X/e/9/e92a040583500c23e3169721768f7eddcb94fbce.gif)

---

<div class="post-metadata">

**Author:** ![Rob](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/rob/32/84134_2.png) [@Rob](https://forum.wixstudio.com/u/Rob)\
**Post date:** [October 14, 2025, 7:18pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/10 "2025-10-14T19:18:12Z")

</div>

Don’t forget if it worked and solved the issue, mark the solution. It helps @CODE-NINJA and adds to the SEO that this is the solution to the question.

Great work as always Code-Ninja as well by the way.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [October 14, 2025, 7:25pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/11 "2025-10-14T19:25:33Z")

</div>

**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 🙂

---

<div class="post-metadata">

**Author:** ![Rob](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/rob/32/84134_2.png) [@Rob](https://forum.wixstudio.com/u/Rob)\
**Post date:** [October 14, 2025, 7:46pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/12 "2025-10-14T19:46:51Z")

</div>

There’s something nice about seeing the process for various option so no worries there and @infernalviper11 got their solution in the end. 😀

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [November 13, 2025, 7:47pm UTC](https://forum.wixstudio.com/t/dynamic-page-get-boolean-value-from-cms-and-display-hide-item-if-false/74221/13 "2025-11-13T19:47:41Z")

</div>

Closed on November 13, 2025, 7:47pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
