Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Japheth Kosgei 7 posts 37 karma points
    May 06, 2015 @ 10:30
    Japheth Kosgei
    0

    Looping through Media Picker with multiple items

    Hi guys, 

    So this is my first post on Umbraco forums - aplogies in advance if my question sounds stupid OR if I don't frame it right... (ALSO AMAZING PLUGIN LEBLENDER IS - thanks lecoati team).

    I have added a media picker (with selection of multiple items enabled) to my grid... I need to enable user to upload videos in multiple formats for a carousel am working on and I would like to access URLs of all the videos selected per media picker. 

    I am basing my solution on the Carousel view example that comes with Leblender. After tinkering around, I have below code working for me where "video" is my media picker property alias. My question is; is this the best way of doing this? I feel it's too verbose... Maybe someone has a more elegant solution? Thanks!

    Side Question: Also which is the best way to customize CSS used by le blender to display in the grid? I am very new to Umbraco's GRID data type as it is and I can't wrap my head around it...

    @{
    if(item.GetValue<string>("video") != "" && item.GetValue<string>("video") != null){
        var vidList = item.GetValue<string>("video").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var vidListCollection = Umbraco.TypedMedia(vidList).Where(x => x != null);
            foreach(var vid in vidListCollection){
                                        <h1>@vid.Urlh1>
                                    }
                                }
        }   
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 06, 2015 @ 11:39
    Alex Skrypnyk
    100

    Hi Japheth,

    Welcome to our community ) 1) You can get video URLs like that:

    var videoUrl = item.GetPropertyValue<string>("video");
                    if (!string.IsNullOrWhiteSpace(videoUrl))
                    {
                        var vidList = videoUrl.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    
                        var vidListCollection = Umbraco.TypedMedia(vidList);
    
                        if (vidListCollection != null)
                        {
                            foreach (var vid in vidListCollection)
                            {
                                <h1>@vid.Url</h1>
                            }
                        }
                    }
    

    Also you can write your own property value converter, documentation here : https://our.umbraco.org/documentation/extending-umbraco/property-editors/value-converters-v7

    http://www.theoutfield.net/blog/2013/04/strongly-typed-property-values-using-property-editor-value-converters-in-umbraco

    Thanks, Alex

  • Japheth Kosgei 7 posts 37 karma points
    May 06, 2015 @ 12:36
    Japheth Kosgei
    0

    Thanks Alex! That works perfectly :) Unfortunately I do not have enough Karmas yet to upvote your answer  but thanks :p

  • Amir Khan 1282 posts 2739 karma points
    May 15, 2015 @ 22:27
    Amir Khan
    0

    Does this work with the current version of LeBlender? I'm using the new Media Picker with multiple images allowed and I get the following error:

    'Lecoati.LeBlender.Extension.Models.LeBlenderValue' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue<T>

    -Amir

  • Japheth Kosgei 7 posts 37 karma points
    May 21, 2015 @ 11:52
    Japheth Kosgei
    0

    Hi Amir, yes it works with latest version. 

    I could be wrong (especially since i haven't looked at the documentation before answering you) but my crystal balls tell me LeBlender exposes its own model to the partial view (BlenderModel). I think this model doesn't have a definition of 'GetPropertyValue' as Umbraco Render Model does. What exactly are you trying to achieve? List images? perhaps you could try something like below. Let me know if this helps :)

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    
    @if (Model.Items.Any()){ 
        foreach (var item in Model.Items){
            if(item.GetValue<string>("imagePropertyName") != "" && item.GetValue<string>("imagePropertyName") != null){
                //do something with your image...
            }
    
        }
    }
  • Amir Khan 1282 posts 2739 karma points
    May 21, 2015 @ 16:55
    Amir Khan
    0

    HI Japeth, the issue I was having I think (in addition to the GetPropertyValue issue) is that it was stored as CSV. Here's what ended up working for me.

     

    var item = Model.Items.ElementAt(0);

    var imageList = item.GetValue<string>("multiImageSlider");
    if (!string.IsNullOrWhiteSpace(imageList))
    {
    var vidList = imageList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);

    var vidListCollection = Umbraco.TypedMedia(vidList);

    if (vidListCollection != null)
    {
    foreach (var vid in vidListCollection)
    {
    <li><img src="@vid.Url"></li>
    }
    }
    }
    }
Please Sign in or register to post replies

Write your reply to:

Draft