How to hide a section on a dynamic item page when a specific CMS field is blank

I use the below example all the time.
Note the exclamation mark before currentItem, this means ‘if empty’.

Replace:
#yourDatasetID with the ID of your dynamic page dataset
databaseFeildID with the field ID in the CMS you want to check
#itemToHideID with ID of the page item you wish to hide

const currentItem = $w('#yourDatasetID').getCurrentItem();

$w.onReady(function () {
     if (!currentItem.databaseFeildID) { $w("#itemToHideID").collapse(); }
});
2 Likes