Create a hidden video on dynamic page if no data

So I’ve looked around and found some code to hide a video on a dynamic page if there isn’t any data on that perticular page but show it if there is. This is the best I have found:

$w.onReady(function () {
    $w('#dynamicDataset').onReady(()=>{
 if($w('#dynamicDataset').getCurrentItem().videoField){
            $w('#videoPlayer1').show('');
 }
 });
});

However it tells me The “src” property cannot be set to “”
How can I fix this?

  1. The ID of your dynamic dataset is → dynamicDataset ?

Try this one… (not tested).


$w.onReady(function () {
   $w('#dynamicDataset').onReady(()=>{
      let myItem = $w('#dynamicDataset').getCurrentItem();
      let myVideo = myItem.videoField
      if(myVideo){$w('#videoPlayer1').show('fade')}
      else {$w('#videoPlayer1').hide('fade')}
   });
});