Hide Video Player When There Is No Video to Play in Referenced Database

Hello,

I’m aware of this tutorial: Hiding a Video Player When There Is No Video to Play . However, my video URLs are not stored as fields in the main Projects database. My video URLs are stored in a separate Videos database that references the Projects database. How can I modify the code from the tutorial to access video items in a referenced database?

Essentially I would like to iterate through the Video database and if there is no video to play for this particular item page, then hide the video player.

Thank you

You’ll need to follow these steps:

  1. Inside the onReady function for your dataset you’ll need to declare a variable that will store the ID of the current item. It should look something like this:
    let myVariable = $w(“#dataset”).getCurrentItem()._id;
  2. After that you’ll need create a query to the referenced field in your collection using wixData.queryReferenced. There you’ll use the following arguments: “Projects” (name of your name database), myVariable (variable that stores the current item ID), “Videos” (name of the reference field).
  3. If results.items.length > 0, then the video should be played. If else, then the video player should be hidden.

You can find the explanation and examples of using queryReferenced here: https://www.wix.com/corvid/reference/wix-data.html#queryReferenced