Copied to clipboard

Flag this post as spam?

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


  • Balram Narad 37 posts 89 karma points
    Jun 08, 2015 @ 18:50
    Balram Narad
    0

    Multiple Media Picker as a macro parameter

    Hi 

    I have got a macro with a multiple media picker as a parameter, I am trying to get the values and use them in razor macro but I am not getting any values,

    This is the source code showing the macro parameters with value DocumentsFolder is my parameter name.

    <div class="umb-macro-holder ListAllFiles mceNonEditable umb-macro-mce_0"><!-- <?UMBRACO_MACRO macroAlias="ListAllFiles" DocumentsFolder="1069,1070" /> --><ins>

    This is the line in my code that I am expecting to return a string with a value of "1069, 1070")

    var bannerListValue2 = Umbraco.Content(Model.MacroParameters["DocumentsFolder"]); 

    unfortunately my bannerListValue2 is empty

    any help much appreciated

    thanks

    Bal

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 08, 2015 @ 19:57
    Dennis Aaen
    102

    Hi Bal,

    I think that you should be good with the code snippet below. Remember to add the macro parameter to the macro, so the user can choose the folders. And you will need to click the add bottom in there, else is not set.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @*
        Macro to display a gallery of images from media the media section.
        Works with either a 'Single Media Picker' or a 'Multiple Media Picker' macro parameter (see below).
    
        How it works:
            - Confirm the macro parameter has been passed in with a value
            - Loop through all the media Id's passed in (might be a single item, might be many)
            - Display any individual images, as well as any folders of images
    
        Macro Parameters To Create, for this macro to work:
        Alias:mediaIds     Name:Select folders and/or images    Type: Multiple Media Picker
                                                                Type: (note: you can use a Single Media Picker if that's more appropriate to your needs)
    *@
    
    @{ var mediaIds = Model.MacroParameters["mediaIds"]; }
    @if (mediaIds != null)
    {
        <ul class="thumbnails">
            @foreach (var mediaId in mediaIds.ToString().Split(','))
            {
                var media = Umbraco.Media(mediaId);
    
                @* a single image *@
                if (media.DocumentTypeAlias == "Image")
                {
                    @Render(media);
                }
    
                @* a folder with images under it *@
                if (media.Children("Image").Any())
                {
                    foreach (var image in media.Children("Image"))
                    {
                        @Render(image);
                    }
                }
    
            }
        </ul>
    }
    
    @helper Render(dynamic item)
    {
        <li class="span2">
            <a href="@item.umbracoFile" class="thumbnail">
                <img src="@item.umbracoFile" alt="@item.Name" />
            </a>
        </li>
    }
    

    Hope this helps,

    /Dennis

  • Balram Narad 37 posts 89 karma points
    Jun 09, 2015 @ 15:57
    Balram Narad
    0

    Thats great thanks Dennis that worked a treat

    Bal

Please Sign in or register to post replies

Write your reply to:

Draft