Copied to clipboard

Flag this post as spam?

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


  • Søren Chr. 10 posts 100 karma points
    Oct 15, 2015 @ 20:18
    Søren Chr.
    0

    Display images from mediapicker

    Hi all

    Hope you can help with a newbee question, how do I display the images in a foreach loop?

    I can retrive the name but can't display the images.

       @if (CurrentPage.HasValue("sliderImages"))
    
        {
            var imagesList = CurrentPage.SliderImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            var imageCollection = Umbraco.Media(imagesList);
    
                                <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <div class="item">
                    @foreach (var images in imageCollection)
                    {
                        <img src="@images.UrlName" />
                    }
    
                </div>
            </div>
        }
    
  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Oct 15, 2015 @ 20:54
    Marc Goodson
    0

    Hi Soren

    Try:

     <img src="@images.Url" />
    

    in your loop!

    Also, really helpful I found when getting to grips with Umbraco and available properties, is the cheat sheet, that Peter Gregory put together:

    https://our.umbraco.org/FileDownload?id=8866

    regards

    marc

  • Søren Chr. 10 posts 100 karma points
    Oct 16, 2015 @ 11:34
    Søren Chr.
    0

    Thank you for the quick reply.

    I got the cheat sheet and tried with .Url but get this error

    "Cannot resolve a Url for a media item when there is no 'umbracoFile' property defined."

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Oct 16, 2015 @ 12:14
    Bjarne Fyrstenborg
    0

    Hi Søren

    Does your media item has a property with alias "umbracoFile" .. it is the property with the upload datatype (or you might have chosen to use image cropper).

    If it has another alias you can use

    <img src="@image.GetPropertyValue("aliasOfProperty")" />
    

    /Bjarne

  • Søren Chr. 10 posts 100 karma points
    Oct 16, 2015 @ 12:43
    Søren Chr.
    0

    Hi Bjarne

    I am using the "multiple media picker" with alias "sliderImages".

    @foreach (var images in imageCollection)
                                {
                                    <img src="@images.GetPropertyValue("sliderImages")" />
                                }
    

    In developer tools it counts the right amount of images but no src:

    <div class="carousel-inner" role="listbox">
                            <div class="item">
                                    <img>
                                    <img>
                                    <img>
    
                            </div>
                        </div>
    

    Thank you for the help

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Oct 16, 2015 @ 13:08
    Bjarne Fyrstenborg
    0

    Okay, but "slideImages" is the alias of your multiple media picker property in content section, right?

    It picks some media items, so images (or image because it represent 1 media image item) and then inside the loop you can access the properties on the media item.. if you go to Settings --> Media Types --> Image just can see the properties similar to how it works with Document Types.

    Does this give you any result?

    @foreach (var image in imageCollection)
    {
          <img src="@image.GetPropertyValue("umbracoFile")" />
    }
    

    /Bjarne

  • Søren Chr. 10 posts 100 karma points
    Oct 16, 2015 @ 13:25
    Søren Chr.
    0

    enter image description here

      @foreach (var image in imageCollection)
    {
          <img src="@image.GetPropertyValue("umbracoFile")" />
    }
    

    no result.

    I can grab the Url.Name and Url.Id in the loop but Url returns nothing :(

    <div class="carousel-inner" role="listbox">
                                <div class="item">
                                        <img src="slide1">
                                        <img src="slide2">
                                        <img src="slide3">
    
                                </div>
                            </div>
    

    I appreciate your help Bjarne!

    I need to find a good tut on implement a slider in umbraco 7 :)

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Oct 16, 2015 @ 13:44
    Bjarne Fyrstenborg
    100

    Okay, so I guess it is the Slider media items you pick and not the default Image media item?

    Which properties does Media Types --> Slider have?

    Ensure it has umbracoFile if your want to use .Url .. otherwise you should also be able to access the property with:

    @foreach (var image in imageCollection) { 
            <img src="@image.GetPropertyValue("someCustomPropertyAlias")" />
    }
    

    /Bjarne

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Oct 16, 2015 @ 13:51
    Bjarne Fyrstenborg
    0

    Here is an example of similar to yours: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/media-picker

    Can't remember want .Url returns on media items or if it is a typo, because it exists on content nodes.

    Could you try with .UmbracoFile?

    https://our.umbraco.org/documentation/Getting-Started/Design/Rendering-Media/

Please Sign in or register to post replies

Write your reply to:

Draft