Update video URL on dynamic pages

Hi there! I am getting familiar with Wix code, and I would like to create dynamic pages to show the video work my company has done. Ideally, I would be able to add a text column to my database that contains a video URL (youtube, vimeo) that would then update the URL of the video player on my dynamic content page.

However, I cannot see an option to link a video player to the data in my database. Is this possible?

Hi spence,

You can update the video component with some code.

  1. Add the Text field to your database collection to hold the Youtube URL.

  2. Add a dataset to your dynamic page and connect all other elements the regular way.

  3. Add a Youtube video element from the Editor ‘Add Panel’ and use the following code snippet to get the video URL and set it to the video element.

$w.onReady(function () { 
    $w("#dataset1").onReady(()=>{
    let itemObj = $w("#dataset1").getCurrentItem(); 
    $w("#video1").videoUrl = itemObj.url; 
    }); 
});

The code access the dataset and the video elements by their ID. The ID (e.g. dataset1) can be found in the property panel once you select the element in the editor.

The code assumes you called the field in your collection ‘URL’ and hence the field key is ‘url’.
You can find your field key by clicking on the 3 dots icon and ‘Manage Properties’

Hi Spence,
if this is your first go at adding code to your page, we’d love some feedback on the experience.
Good luck!

Ha! It worked! Thank you so much, Ziv!

Yes, this is my first time adding code, so my questions will probably appear very obvious to those more experienced than me! I’m very glad to have the help, and truly excited by the tools in Wix Code.

Hey Spence … I would love to see what you created with Code. Mind sharing a link to your page? :slight_smile:

Way to go Spence!
kudos on the courage to plunge into code. It’s very satisfying for us to have users step out of their comfort zone. Keep it up!

Thanks Ziv!

Nayeli - I’m still very much putting it together, but I would be more than happy to share once it’s published! :slight_smile:

Hey guys, so I’m still building but I have managed to put together a video portfolio, sorted by the type of video production, with dynamic pages for each video. I have MANY more videos to add, but for now it’s working and looking good! Thank you so much for your help!

https://www.richter10point2.com/portfolio

Hi,
i am totally new in this field and i try to do the same for my website but its not working for me. maybe i am missing something. so please share video link, if same available you please elaborate in more details set by set.

thanks in advance

Hi @gdharam21 ,
Please post a new thread and share with us the code you’ve written and the issue you were experiencing.

Thanks,
Tal.

Thank you for sharing this info with us. We are also video production company . So this information can be very helpful for us.

This looks great and is similar to what I am trying to achieve on my website (a dynamic page with holding images and the ability to add videos.) I am SUCH a novice - can anyone help?