Copied to clipboard

Flag this post as spam?

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


  • Sagar 74 posts 275 karma points
    May 20, 2016 @ 11:11
    Sagar
    0

    Image Gallery

    How to create Image Gallery according to Folder Suppose, I am having 2 folders F1 and F2 i want images from F1 to be displayed first and then F2 in my frontend

    Can anyone Help?

  • M T 35 posts 212 karma points
    May 20, 2016 @ 11:50
    M T
    1

    Hi Sagar,

    Easy with a little MVC

    Create a controller :-

     class GalViewModel
    {
        public IEnumerable<string> Images { get; set; }
    }
    
    // controller
    
    public ActionResult GalAction()
    {
        var model = new GalViewModel()
        {
            Images = Directory.EnumerateFiles(Server.MapPath("FOLDERLOCATION"))
                              .Select(fn => "FOLDERLOCATION" + Path.GetFileName(fn))
        };
        return View(model);
    }
    

    Then create a partial view for the controller with the loop :-

    @foreach(var image in Model.Images)
    {
        <img src="@Url.Content(image)"  />
    }
    

    Of course you can do so much more but this is the most basic way i could think of doing it.

    Regards, M

  • Sagar 74 posts 275 karma points
    May 20, 2016 @ 12:21
    Sagar
    0

    Thanks M T

  • Sagar 74 posts 275 karma points
    May 20, 2016 @ 12:32
    Sagar
    0

    What if I select Multiple Folders containing images in each from multi media Picker?

  • Sagar 74 posts 275 karma points
    May 21, 2016 @ 06:53
    Sagar
    101

    Ok I got it by Myself

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var ms = ApplicationContext.Current.Services.MediaService;
    }
    @{
        char[] splitChar = { ',' };
        string[] ids = CurrentPage.file.ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
        if (!string.IsNullOrEmpty(CurrentPage.file))
        {
            foreach (var x in ids)
            {
                char[] splits = { ',' };
                var dynamicmediaitem = Umbraco.Media(x);
                <h3>@dynamicmediaitem.Name</h3>
                <br/>
                foreach (var children in dynamicmediaitem.Children)
                {
                    if (children.Children.Any())
                    {
                        <img [email protected] />
                    }
                    else
                    {
                        <img [email protected] />
                    }
                }
                <img [email protected] />
                <br/>
            }
        }
    }
    
  • 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