Copied to clipboard

Flag this post as spam?

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


  • Sjoerd Stottelaar 9 posts 131 karma points
    Feb 11, 2019 @ 13:34
    Sjoerd Stottelaar
    0

    Render media in Umbraco 8

    What is the best way to render media (image) in a template using Umbraco 8? I can't get it to work and the documentation doesn't say much about it for version 8. At the moment I've tried:

    nieuwsItem.Value("artikelAfbeelding");
    

    Which returns an object called:

    Umbraco.Web.PublishedModels.Image
    

    When trying to get the URL of that image I get an error. I've tried getting the URL using: nieuwsItem.Value("artikelAfbeelding").Url; which returns an error. I presume this has to do with the new ModelBuilder in Umbraco 8, but I can't figure it out.

    Is there any documentation that specifies how this should be done?

    Thanks!

  • Sjoerd Stottelaar 9 posts 131 karma points
    Feb 11, 2019 @ 15:14
    Sjoerd Stottelaar
    102

    I've found the solution for my problem. I forgot to cast the value as an IPublishedContent item:

    var image = nieuwsItem.Value<IPublishedContent>("artikelAfbeelding");
    

    After that I can call the URL like so:

    @image.Url
    

    Maybe this is useful to somebody someday!

Please Sign in or register to post replies

Write your reply to:

Draft