Hide a CMS text field if no content

Hi all,

I’ve got a CMS case study. Each case study has a series of text fields and rich text fields. For a couple of the case studies, some of the fields aren’t relevant. Can anyone let me know how I hide the field if there is no content?

Thanks

Of course, that’d depend on your usage though, are those case studies in a repeater? A dynamic page? Something else?

Repeater

$w('#caseStudiesRepeater').onItemReady(($item, data) => {
    if (!data.textField) $item('#textField').hide() // or .collapse()
})

Dynamic Page

const dataset = $w('#caseStudiesDataset')
dataset.onReady(() => {
    const item = dataset.getCurrentItem()
    if (!item.textField) $w('#textField').hide() // or .collpase()
})

This should givwe you a general outline of the functionality

1 Like