# Collapse the section if it does not contain any CMS data

**URL:** <https://forum.wixstudio.com/t/collapse-the-section-if-it-does-not-contain-any-cms-data/54001>\
**Category:** Ask the community\
**Tags:** technical-talk, cms, code, question\
**Created:** [November 21, 2023, 3:51pm UTC](https://forum.wixstudio.com/t/collapse-the-section-if-it-does-not-contain-any-cms-data/54001 "2023-11-21T15:51:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bulubulu](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bulubulu/32/81354_2.png) [@Bulubulu](https://forum.wixstudio.com/u/Bulubulu)\
**Post date:** [November 21, 2023, 3:51pm UTC](https://forum.wixstudio.com/t/collapse-the-section-if-it-does-not-contain-any-cms-data/54001/1 "2023-11-21T15:51:28Z")

</div>

Hi there,

I have a CMS called “Awards” which refers to the “Projects” CMS. On the dynamic page displaying the Projects items, I would like the section containing the Awards to collapse if the project does not have any Awards linked to it. Awards are manually filtered in the menu. This code seems to work, but could you please tell me if this is the correct method?

```javascript
import wixData from 'wix-data';

const repeaterAwards = '#repeaterAwards';
const sectionAwards = '#sectionAwards';

$w.onReady(function () {
    $w('#dataset1').onReady(() => {
        wixData.query("Awards").find()
            .then(awardsRes => {
                if ($w('#dataset1').getTotalCount() === 0) {
                    $w(sectionAwards).collapse();
                } else {
                    $w(sectionAwards).expand();
                }
            });
    });
});

```

---

<div class="post-metadata">

**Author:** ![oakstreetassociates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/oakstreetassociates/32/27732_2.png) [@oakstreetassociates](https://forum.wixstudio.com/u/oakstreetassociates)\
**Post date:** [November 21, 2023, 6:08pm UTC](https://forum.wixstudio.com/t/collapse-the-section-if-it-does-not-contain-any-cms-data/54001/2 "2023-11-21T18:08:54Z")

</div>

There’s never just one way to do anything, right? If it works, great but yes there are always better (more efficient) ways to do this.

In this case, if you’re using a repeater, you can just set that if it does not have any item data (values) to collapse. I cannot see your website or how it works so if it works then you can just leave it as is. If everything is connected to a dataset then the repeater on item ready or for each item (if changes without changing the page) would work fine. You would use $item instead of $w of course.

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [November 22, 2023, 4:57pm UTC](https://forum.wixstudio.com/t/collapse-the-section-if-it-does-not-contain-any-cms-data/54001/3 "2023-11-22T16:57:34Z")

</div>

As @oakstreetassociates mentioned, there’s multiple ways of doing something with code that will result in the same outcome.

Looking at the code (and assuming it’s the only code on the page), I’d potentially remove the `wixData.query` part. The dataset is already getting the data and the query is getting the data again, but not being used anywhere.

I’d potentially go with this, but again, it depends on the current setup you have 🙂

```javascript
const sectionAwards = '#sectionAwards';

$w.onReady(function () {
    $w('#dataset1').onReady(() => {
        if ($w('#dataset1').getTotalCount() === 0) {
            $w(sectionAwards).collapse();
        } else {
            $w(sectionAwards).expand();
        }
    });
});

```
