How to access OEmbedPart to display youtube video

Topics: Customizing Orchard, Writing modules
Dec 3, 2014 at 2:19 AM
Hi,

I have created a content type called ProductPack which contains two MediaLibraryFields. One for the pack image and one for a link to a youtube video. It also contains a few more fields a custom product part and a few other core parts.

I have a module for a product which defines the product part with a few fields for prices etc.

I'm not sure if this is the best way to go but have create a shape override to override the whole content details display for the productpack and am manually rendering out the display with a bunch of if statements.

So for instance I access the ProductPack image like
var productImage = Model.ContentItem.Product.ProductImage;

Then I have
@if (productImage != null && productImage.MediaParts.Count > 0)
    {
        <img src="@productImage.MediaParts[0].MediaUrl" />
    }
My question is how can I do this for a MediaLibraryPickerField based on OEmbedPart?
I cannot seem to access the Url for the youtube video to render out.

Or is the approach I have taken the wrong way to do this?
Coordinator
Dec 10, 2014 at 2:22 AM
Dec 10, 2014 at 4:27 AM
Thanks Bertrand! Exactly what I was after.

Note: Needed to add @using Orchard.ContentManagement namespace to use the As<> call, otherwise it tries to use it from linq namespace.