Copied to clipboard

Flag this post as spam?

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


  • Christine 115 posts 288 karma points
    Apr 04, 2014 @ 17:52
    Christine
    0

    Media Picker does not display image on front end

    I have an issue with the Media Picker data type

    It will select an image from the media files in the back office and display it.

    However, in the front end, the image does not display. Inspecting the element I see this:

    img src="1106" alt

    the src is only displaying the id of the image, not the file path.

    Also, how can I make it possible for the user to add a value to the alt?

     

    Thanks in advance!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 04, 2014 @ 17:57
    Jeavon Leopold
    0

    Hi,

    If it's a single item media picker and you are using MVC then this is what you need to do:

    @{      
        if (CurrentPage.HasValue("mainImage")){                                         
            var dynamicMediaItem = Umbraco.Media(CurrentPage.mainImage);
            <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
        }
    }
    

    Are you using Umbraco v6 or v7?

    Jeavon

  • Christine 115 posts 288 karma points
    Apr 07, 2014 @ 16:14
    Christine
    0

    I'm using Umbraco V7

    I have already in the template:

    img src="@Umbraco.Field("sbPageGraphic")" alt="@Umbraco.Field("altText")" /

    how do I integrate this with the code you gave me so that it will find the file path of the image and not just the id?

    Thanks in advance!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 07, 2014 @ 16:39
    Jeavon Leopold
    100

    Hi Christine,

    Just like this:

    @{
        if (CurrentPage.HasValue("sbPageGraphic"))
        {
            var dynamicMediaItem = Umbraco.Media(CurrentPage.sbPageGraphic);
            <img src="@dynamicMediaItem.Url" alt="@CurrentPage.altText" />
        }
    }
    

    Jeavon

  • Christine 115 posts 288 karma points
    Apr 07, 2014 @ 17:10
    Christine
    0

    Yes that did it - thanks so much!

Please Sign in or register to post replies

Write your reply to:

Draft