Copied to clipboard

Flag this post as spam?

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


  • Renee Haas 18 posts 109 karma points
    Nov 01, 2016 @ 21:06
    Renee Haas
    0

    Display Media Folder Images in Partial View

    I have utilized the following code inside of a partial view, but the issue I am running into is @media.umbracoFile is outputting extra info such as the focalPoint, whereas I just want the src.

    @{
                    DynamicMedia folder = new DynamicMedia(1128);
    
                    if (folder != null && folder.Children.Items.Count() > 0)
                    {
                        foreach (dynamic media in folder.Children.Items)
                        {
                            <div class="three" style="text-align:center;">
                                <img src="@media.umbracoFile" alt="@media.Name" style="width:100%; max-width:229px; max-height:116px; text-align:center;" />
                            </div>
    
                        } 
                    }                             
                }
    
  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Nov 02, 2016 @ 07:26
    Dennis Adolfi
    100

    Hi Renee.

    Here is a working example based on your code, but with strongly typed media items as IPublishedContent, that way you dont have to work with dynamics.

    @inherits UmbracoTemplatePage
    @{
        IPublishedContent folder = Umbraco.TypedMedia(1071);
    
        if (folder != null && folder.Children.Any())
        {
            foreach (IPublishedContent media in folder.Children)
            {
                <div class="three" style="text-align:center;">
                    <img src="@media.Url" alt="@media.Name" style="width:100%; max-width:229px; max-height:116px; text-align:center;" />
                </div>
    
            }
        }
    }
    

    Hope it helps!

    Take care!

  • Renee Haas 18 posts 109 karma points
    Nov 02, 2016 @ 16:19
    Renee Haas
    1

    Brilliant! Thank you so much.

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Nov 02, 2016 @ 18:26
    Dennis Adolfi
    0

    Thank you Renee!! Take care, have a great day!

  • 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