Dynamic Pages adding element only on one item

How can I add an element to a dynamic page so that it only appears on one specific item, and not on all dynamic pages?

You need to code it. So if the field in the CMS is blank it will not display

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

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

Exactly as @Dan_Suhr mentioned :backhand_index_pointing_up:


Only thing I’d add is wrapping it with an onReady for the dataset too (make sure it’s ready before getting the currentItem).

$w.onReady(function () {
    $w('#yourDatasetID').onReady(() => {
        const currentItem = $w('#yourDatasetID').getCurrentItem();

        if (currentItem.databaseFieldID) {
            $w("#itemToHideID").expand();
        }

    })
});

And (personally), I’d make the element collapsed by default in the code properties panel, and then “if the collection has the item, expand the element”

2 Likes