# Collapse Dynamic section if no content in CMS

**URL:** <https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694>\
**Category:** Ask the community\
**Tags:** cms, wix-studio, code\
**Created:** [February 20, 2026, 3:39pm UTC](https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694 "2026-02-20T15:39:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user3470](https://avatars.discourse-cdn.com/v4/letter/u/e495f1/32.png) [@user3470](https://forum.wixstudio.com/u/user3470)\
**Post date:** [February 20, 2026, 3:39pm UTC](https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694/1 "2026-02-20T15:39:42Z")

</div>

**I’m having trouble with**

I have a CMS populated with a series of case studies. Each field in the CMS is shown in section on the page. the content type varies - images, videos, rich text etc.

One of the fields is in iFrame pointing to external website, but not every case study has this option.

How do I collapse the sections where there is no data? Rather than have a gap?

Please let me know the code I need to add. I’m not a coder so a step by step guide would be useful. Thanks

**Working in**  
Wix Studio Editor,

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [February 21, 2026, 9:15am UTC](https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694/2 "2026-02-21T09:15:09Z")

</div>

Instead of collapsing when not available, I’d actually go the other way around, and only expand the section when data is available. The result is the same, just slightly more effcient.

I’m taking some naming liberties, seeing as I do not know your field and element names

```ts
const dataset = $w('#dynamicDataset')
dataset.onReady(() => {
    const item = dataset.getCurrentItem()
    if (item.iFrameUrl) $w('iFrameSection').expand() 
                        // mark collapsed by default
})

```

---

<div class="post-metadata">

**Author:** ![user3470](https://avatars.discourse-cdn.com/v4/letter/u/e495f1/32.png) [@user3470](https://forum.wixstudio.com/u/user3470)\
**Post date:** [February 23, 2026, 12:37pm UTC](https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694/3 "2026-02-23T12:37:15Z")

</div>

Many thanks for this.

The only issue I can see, is that the iFrame links to individual case studies within the CMS so I can’t add a generic URL to the ‘master’ page if that makes sense as they vary in each case study.

In fact now I’ve looked at it again, I’m not 100% sure they are even iFrames. I think I have a rich text container pointing to URL and this is hosted elsewhere, but the same problem occurs in that I can’t specify the iFrame or container in the master page. So I guess this bit:

if ( **item.iFrameUrl** )…

wouldn’t work in this case

Would I need to change the code for this?

Sorry, I know very little about code!

Thanks in advance

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [March 4, 2026, 1:31pm UTC](https://forum.wixstudio.com/t/collapse-dynamic-section-if-no-content-in-cms/76694/4 "2026-03-04T13:31:43Z")

</div>

Sorry for the delay, I’m not as active as I used to be here  
I don’t think I understand what you mean here
