Copied to clipboard

Flag this post as spam?

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


  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 02:27
    Paul Brown
    0

    Pick up media folder dynamically

    Hello

    I am trying to loop through a media folder and display the images on the page.

    Does anyone know how I can replace the hardcoded folder id with that set by the user in the "Content" section using the "Standard Media Picker"?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "_Layout.cshtml";
    }
    @{
      var gallery = new umbraco.MacroEngines.DynamicMedia(1063);
    }


    @foreach (dynamic item in gallery.Children.Items)
     {

                    @item.name

     }

     

     

    Thanks Paul

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 07:32
    Fuji Kusaka
    0

    Hi Paul,

    You could check if the Media Picker holds a value, if so then use it numerical value in MediaById.

    if(!String.IsNullOrEmpty(Model.MediaPickerAlias)){
     var gallery = @Model.MediaById(Model.MediaPickerAlias);
    foreach(dynamic item in gallery.Children){
    @item.Name
    }
    }

    Hope this helps

    Fuji

  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 10:36
    Paul Brown
    0

    Hey Fuji

    Thanks for the reply! I've added the code but get this error below, am i missing a @inherits maybe?

    Error:

    CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'MediaById' and no extension method 'MediaById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
    Line 5:  
    Line 6:  if(!String.IsNullOrEmpty(Model.MediaPickerAlias)){
    Line 7: var gallery = @Model.MediaById(Model.MediaPickerAlias); Line 8:    foreach(dynamic item in gallery.Children){
    Line 9:      @item.Name
  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 11:58
    Fuji Kusaka
    0

    Hi Paul,

    Try using this code in your template where you are planning to add this functionality or may be just create a new cshtml file from the developers section.


    @{
    if(!String.IsNullOrEmpty(Model.MediaPickerAlias)){
     var gallery =@Model.MediaById(Model.MediaPickerAlias);
      foreach(dynamic item in gallery.Children){
        @item.Name
       }
    }
    }
  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 12:41
    Paul Brown
    0

    Hey Fuji

    Sadly still not working for me...dont suppose I could ZIP it all up and email you it and see if you can see the issue?

    Cheers Paul

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 12:51
    Fuji Kusaka
    0

    Yes you can send it to me

  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 13:11
    Paul Brown
    0

    hey i dont have your email but i tweeted u a link to my public drop box :

    thanks :)

  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 14:01
    Paul Brown
    0

    :) were u able to access file okay? Cheers Paul

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 19, 2013 @ 19:08
    Fuji Kusaka
    0

    It should be working now .

  • Paul Brown 39 posts 80 karma points
    Apr 19, 2013 @ 22:51
    Paul Brown
    0

    totally awesome - i am very thankful to you for this :)

    ---

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft