BTW, noticed that this code only works for the buttons. If you have other elements, image for example, I found this code works better for images:
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(); }
});