Can one media item show either video from Youtube Or image from website?

I am trying to find a way to have an area on my home page that will show either a video (from Youtube or an image that I upload, through a collection. Any idea how I could do that?
I don’t even think a show/ hide code based on an empty/not empty field would work because a video box will always be populated with the EditorX default video. Or am I mistaken? Can anyone help with how do I set the code for this?
Thanks!!

Hi,

Great question!

You can configure the logic with code in many ways, but I would recommend the following:

Step 1 - The Design
Add both the image container and video container on top of each other. Collapse both of them

Step 2 - The Collection
Set the collection columns to include a column for “Media type”, the field values could be “image”/“video”.

Connect the repeater to data

Step 3 - The Code
Use forEachItem( ) to run a function on all items where we check what “Media Type” is assigned and we use this to expand the required media.

Let us know if you have any questions.
Thanks

Thanks for your help!
For the Could “Media type” field, do you suggest it being a boolean or a text field? Do I then set up two more columns, one for video and one for image?
For the code, is there a basic tutorial I can follow for using Velo with collections and datasets? I never used velo with collections before so I don’t even know how to call the collection fields in the code.

I see the forEachItem( ) is for repeater elements only? (Meaning I need to set my image and video inside a repeater?)

Thanks again.