Collapse Dynamic section if no content in CMS

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,

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

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

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

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