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

How can I hide a particular section on a dynamic item page when a specific CMS field is blank?

Working in Wix Studio Editor

I have a dynamic item page set up for football player profiles. I have a section that I want to show the “Awards” , which are linked to a field in a CMS. However only some players have awards listed in the CMS. So I’d like to hide this section when that CMS field is blank for a particular player.

This is the code I’ve tried, but it is incorrect.

$w(“#playerStats”).onReady( () => {

    if (awardsReceived) {
        $w("#section64").hide();
    } else {
        $w("#section64").show();
    }
});

});

I’d be grateful for any assistance.

Hey, I’m happy to help! Could you send me a screenshot of the code panel with the page.

This code works

$w.onReady(function () {

$w("#dynamicDataset").onReady( () => { 
       let item = $w("#dynamicDataset").getCurrentItem(); 

       if (item.onlineBookingLink) { //change to field key
          $w("#button1").show();
       } else {
          $w("#button1").collapse();
          $w("#button1").hide();
       }

Hey Koen, that’d be fantastic thank you.
Here’s a screenshot of the page. The code in my question is all that’s currently in the code panel. The section I’m trying to hide when the CMS field is empty, is the section where the field is on if that makes sense. It’s the “awards received” container (which is on it’s own section.)

Hi Dan, this doesn’t seem to work unfortunately.

show me the code you used - I have this working on a site with no problems.

ps… go QLD

1 Like

Thanks Dan – Yes, it’s entirely possible I’ve put this in incorrectly. Here’s a screenshot:

so you have an error with the dataset name #PlayerStats. Check you have the correct name and see if that fixes the issue. I have not tested this code with a whole section, just individual elements.

if you are still having issues let me know and I can help fix.

Hmm. it says it’s that name when I go to the settings…
Screenshot 2024-06-25 at 8.46.12 AM

Ok just realised that’s the collection ID not the dataset name. Changed it, but it still doesn’t work. Yes, I’d love some help to fix please.

Would you be willing to get on a quick 5m virtual call so that i can help you out with this?

@Teri_Sutherland - I have messaged you.

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

Boom! That did it! Thanks so much for your help!

1 Like