Copied to clipboard

Flag this post as spam?

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


  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 12:19
    Gary Burnett
    0

    How do I Use 'List Images From Media Folder' Snippet in Partial View Macro?

    I am very new to Umbraco and wish to create a Gallery. I need to retrieve I list of images and add the list to a page for furthur processing by Jquery. I have tried using the snippet included in Umbraco 7.1 and creating macro parameters but am unsure of the complete procedure to get this to work. Please help. Thanks

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 15:05
    Jeavon Leopold
    0

    Hi Gary,

    Welcome to Our!

    Ok, first question is do you need a partial view macro for this or could you just write the code into your view? Second question is how are you going to select the folder that contains the images, a media picker perhaps?

    Jeavon

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 15:10
    Gary Burnett
    0

    Hi Jeavon,

    thanks for your interest.

    I have just been following the comments in the provided snippet which are:- 

       "Macro to display a gallery from a media folder. Add the below parameter to the macro
        and use it to point the macro at a specific media folder to display it's content as
        a simple list.

        Macro Parameters To Create, for this macro to work:
        Alias:mediaId     Name:Media Folder ID    Type:Single Media Picker"

    Gary

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 15:19
    Jeavon Leopold
    0

    Ok, so you have the macro and you have created the macro parameter, now you need to insert into a template. To do this you click the third icon in the template toolbar and then select the macro, does that make sense?

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 15:23
    Gary Burnett
    0

    Yes, that is exactly what I did, but I must be doing something wrong because I just get 'The yellow screen of death' :-(

    Gary

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 15:32
    Jeavon Leopold
    0

    Ok, does the Yellow Screen have any error message in it?

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 15:48
    Gary Burnett
    0

    It says

    Line 7:  *@
    Line 8: 
    Line 9: @if (Model.MacroParameters["mediaId"] != null)

    Line 10: {
    Line 11:      @* Get the media folder as a dynamic node *@

    Gary

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 15:57
    Gary Burnett
    0

    Just tried this again and got;-

    Error loading Partial View script (file: ~/Views/MacroPartials/gallery.cshtml)

    where the macro is inserted in the template.

    I do appreciate your help with sorting this

    Gary

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:00
    Jeavon Leopold
    0

    Ok, in your template does your render macro contain the id?

    Something like this:

    @Umbraco.RenderMacro("Gallery", new {mediaId="1079"})
    
  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 16:00
    Gary Burnett
    0

    I expected there to a be the Media Folder ID property appearing on the properties tab of the page generated from that template, but that doesn't appear.

    Gary

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 16:01
    Gary Burnett
    0

    No the template doesn't show the ID

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:02
    Jeavon Leopold
    0

    You should be presented with the media picker to select the folder when you insert the macro into the template, then the code I posted above should be generated. If that's not happening, it sounds like the macro parameter didn't save when you added it...?

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:05
    Jeavon Leopold
    0

    You macro parameter setup should look something like this

    enter image description here

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 16:14
    Gary Burnett
    0

    Parameters are similar to yours except Name is "Media Folder ID"

    maybe there is a better way to acheive this?

    Gary

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:18
    Jeavon Leopold
    0

    Alias is the important one, do you have the capital I, in "mediaId"?

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:21
    Jeavon Leopold
    0

    When you insert the macro into the template do you need get a dialog like this one below after you've selected your macro?

    enter image description here

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:23
    Jeavon Leopold
    0

    The alternative would be to write this code directly into the view without using the macro at all (change myMediaPicker to your media picker property alias)

    e.g.

                @{
                    var myMediaPicker = CurrentPage.myMediaPicker;
                    var mediaFolder = Umbraco.Media(myMediaPicker);
    
                    if (mediaFolder.Children.Any())
                    {
                        <ul class="thumbnails">
                            @* for each item in children of the selected media folder *@
                            @foreach (var mediaItem in mediaFolder.Children)
                            {
                                <li class="span2">
                                    <a href="@mediaItem.Url" class="thumbnail">
                                        <img src="@mediaItem.Url" alt="@mediaItem.Name" />
                                    </a>
                                </li>
                            }
                        </ul>
                    }
                }
    
  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 16:27
    Gary Burnett
    0

    I did have a capital I and D so that has now been corrected and I do get to choose a media folder when I insert the macro so the code in the template looks like this:-

    @Umbraco.RenderMacro("Gallery", new {MediaId="1084"})
    

    gary

  • Gary Burnett 10 posts 30 karma points
    Aug 23, 2014 @ 16:38
    Gary Burnett
    0

    Just used your code,

    works perfectly, think i will use it if that's ok? 

    Thank you so much for your time and patience it is very much appreciated.

    Gary

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:39
    Jeavon Leopold
    0

    Ok, the "MediaId" needs to exactly match what you have in the template and Macro definition, e.g

    In the partial view:

    @if (Model.MacroParameters["MediaId"] != null)
    {
        @* Get the media folder as a dynamic node *@
        var mediaFolder = Umbraco.Media(Model.MacroParameters["MediaId"]);
    
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Aug 23, 2014 @ 16:55
    Jeavon Leopold
    0

    Yes of course, no problem.

  • 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