Copied to clipboard

Flag this post as spam?

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


  • Mark 17 posts 88 karma points
    Mar 29, 2014 @ 02:41
    Mark
    0

    Umbraco 7 - Showing media picker image in a template

    can someone please supply me with the require code to display an image from a media picker "featureImage" inside a template. i am guessing it is very simple but i just cant figure it out ... 

    here is my html code

    <div class="banner_dish">

                   @Umbraco.Field("featureImage")

                    <div class="banner_dish_heading">

                    <h3>@Umbraco.Field("featureHeading") </h3>

                        <p>@Umbraco.Field("featureIntro")</p>

                    </div> 

     

    .............

    I tried this  code but it didnt work  ... 

    @if (string.IsNullOrWhiteSpace(CurrentPage.featureImage.ToString()) == false)

    {

    <img src="@CurrentPage.Url("featureImage")" alt="" />

    }

    .................

    is there a manual somewhere that tells you how to do simple things like adding an image to a template 

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 29, 2014 @ 08:22
    Jeavon Leopold
    0

    Hi Mark,

    There is documentation here that shows how to output images from a multiple media picker which is new to v7. Or for a single media picker you can see the sample code here which is the same on v6 and v7 (look at the MVC section)

    Essentially you need this snippet

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

    Jeavon

  • Mark 17 posts 88 karma points
    Mar 29, 2014 @ 11:33
    Mark
    0

    thank you Jeavon you rock ... that worked ... 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 29, 2014 @ 12:18
    Jeavon Leopold
    1

    Awesome!

    Actually, thinking about it, it's probably a little bit better to update to:

        <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
    

    Thanks,

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft