Copied to clipboard

Flag this post as spam?

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


  • Darren Wilson 218 posts 556 karma points
    Jun 15, 2015 @ 16:32
    Darren Wilson
    0

    Display contents of Multiple Media Picker in macro.

    Hi Folks, I'm trying to display a list of documents added to node using the Multiple Media Picker - like a list of downloads.

    I've created a macro and associated XLST file base upon something I've found out there:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @if(Model.Content.HasValue("downloadPublicDocuments"))
    {
        var docsList = Model.Content.GetPropertyValue<string>("downloadPublicDocuments").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var docsCollection = Umbraco.TypedMedia(docsList).Where(x => x != null);
    
        var count = 0;
        var closed = false;
        var opener = "<div class='col-sm-6'>";
        var closer = "</div>";
    
        foreach (var docItem in docsCollection)
        {               
            if(count == 0)
            {               
                closed = false;
                @Html.Raw(opener);
            }
    
            var bytes = Convert.ToInt64(docItem.GetPropertyValue("umbracoBytes"));
            var inmb = bytes / 1048576;
            var inkb = bytes / 1024;
    
            <div class="file">
                <h1>@docItem.Name</h1>
                <p>File Type: @docItem.GetPropertyValue("umbracoExtension").ToString().ToUpper() | 25 March 2015 | @inkb kb<p>
            </div>
    
            if(count == 1)
            {
                closed = true;
                @Html.Raw(closer);
                count = 0;
            }
            else
            {
                count++;
            }
        }   
    
        if(!closed)
        {
            closed = true;
            @Html.Raw(closer);
        }
    }
    

    The page returns no documents even though I've attached them to the node. Is there an easier was of listing the media attached to a node? Any help will be greatly appreciated.

    Thanks in advance. Darren

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Jun 15, 2015 @ 17:34
    Dennis Aaen
    2

    Hi Darren,

    Since you are using Umbraco 7, then you will need to use Razor. You could use a partial views or partial view macros.

    Try to see this documentation about how to get data from a multiple media picker. https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors-v7/Media-Picker

    Hope this helps,

    /Dennis

  • Darren Wilson 218 posts 556 karma points
    Jun 16, 2015 @ 09:11
    Darren Wilson
    0

    Thanks Dennis, I'll give this a try. Darren

  • Darren Wilson 218 posts 556 karma points
    Jun 16, 2015 @ 12:26
    Darren Wilson
    2

    Hi Dennis,

    With a bit of tweaking based on what you suggested and what I've already done - managed to get this Partial View Macro working. Basically, it lists media, file type, size and date - ideal for download pages if anyone is interested!

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    @if (CurrentPage.HasValue("caseStudyImages")) { var docsList = Model.Content.GetPropertyValue

        var count = 0;
        var closed = false;
        var opener = "<div class='col-sm-6 customers'>";
        var closer = "</div>";
    
        foreach (var docItem in docsCollection)
        {               
            if(count == 0)
            {               
                closed = false;
                @Html.Raw(opener);
            }
    
            var bytes = Convert.ToInt64(docItem.GetPropertyValue("umbracoBytes"));
            var inmb = bytes / 1048576;
            var inkb = bytes / 1024;
    
            <div class="file-customer">
                <h1>@docItem.Name</h1>
                <p>File Type: @docItem.GetPropertyValue("umbracoExtension").ToString().ToUpper() | 25 March 2015 | @inkb kb<p>
            </div>
    
            <div class="file-icon"><a href="@docItem.Url" target="_blank"><img src="/css/img/download.png"></a></div>
    
            if(count == 1)
            {
                closed = true;
                @Html.Raw(closer);
                count = 0;
            }
            else
            {
                count++;
            }
        }   
    
        if(!closed)
        {
            closed = true;
            @Html.Raw(closer);
        }
    }   
    

    Cheers

    Darren

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies