Copied to clipboard

Flag this post as spam?

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


  • David Hyslop 22 posts 155 karma points
    Oct 12, 2017 @ 12:16
    David Hyslop
    0

    Get URL of Media Picker Image

    Hi

    If anyone could offer any help would be greatly appreciated. This one is driving me mad.

    I'm displaying some child pages in a template and have an image in the pages that I'd like to display and am strggling getting the Url of that image.

        @{
                    var navitem = CurrentPage.Children.Where("Visible");
    
    
                }
    
                @{foreach (var item in navitem)
    
                    {
                        <div class="col-xs-4">
                            <div class="news-item">
    
                                <h2> @item.pageTitle</h2>
                                <p> <i class="fa fa-calendar" aria-hidden="true">@item.UpdateDate.ToString("dd MMMM yyyy")</i><br /></p>
                                <p class="news-intro">
    
                                    @item.introText
    
                                </p>
    
                           <img src="@item.newsImage">
                            </div>
                        </div>
                    }
    
                }
    

    Its @item.newsImage where I'm just getting the ID. Does anyone know how to convert that to the URL.

    Thanks.

  • Alex Skrypnyk 3986 posts 14120 karma points mvp
    Oct 12, 2017 @ 12:20
    Alex Skrypnyk
    100

    Hi David

    Use this code:

    <img src="@Umbraco.Media(item.newsImage).Url">
    

    Also be aware that dynamics isn't the best practice for using.

    Thanks,

    Alex

  • David Hyslop 22 posts 155 karma points
    Oct 12, 2017 @ 12:40
    David Hyslop
    0

    Thanks Alex, little change but worked fine.

      @{int newsImageId = item.newsImage;
                                }
    
                                <img src="@Umbraco.Media(newsImageId).Url">
    
  • Alex Skrypnyk 3986 posts 14120 karma points mvp
    Oct 12, 2017 @ 13:17
    Alex Skrypnyk
    0

    Glad to help you!

    Have a great evening!

Please Sign in or register to post replies

Write your reply to:

Draft