Hide/show files from CMS

I have a CMS collection linked to a dynamic page. Each row of the field has multiple single document fields.

The document fields are connected to buttons on the dynamic page (so user can click to download). However, not all rows of the CMS have files in the single document field.

Is there a way of hiding the button on the dynamic page if there is no content in the document field?

Alternatively, is there a way of displaying all files in a multidocument cms field on a page and have them downloadable?

I’m in WIX studio

If on the dynamic page:

  • replace ‘document1’ with the CMS field name;
  • replace ‘button1’ with the ID of your button;
  • repeat the if statement for each document/button
const currentItem = $w('#dynamicDataset').getCurrentItem();

$w.onReady(function () {
    if (!currentItem.document1) { $w(“#button1”).collapse(); }
    if (!currentItem.document2) { $w(“#button2”).collapse(); }  // if 2nd item required
});