Copied to clipboard

Flag this post as spam?

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


  • Carlos Luis Lachapelle Rivera 4 posts 73 karma points
    Oct 14, 2019 @ 20:17
    Carlos Luis Lachapelle Rivera
    0

    Show image in Article item

    Well, I have a problem like my Umbraco platform, I am trying to create a content blog and I want to show the header image and it doesn't show up.


        <header class="major special">
            <h2>@Model.Value("articlesTitle")</h2>
        </header>
        <img src="@Model.Value("ArticleImage")"/>
        <p>@Model.Value("fechaDeNoticia")</p>
        <p>@Model.Value("articleContent")</p>
    
    </div>
    

    I am trying to call the image node in the template and tried anyway to form and it doesn't work for me.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Oct 14, 2019 @ 22:57
    Nik
    0

    Hi Carlos,

    What sort of property is your image property? This influences how best to access it.

    Assuming that the ArticleImage property on your blog post is a media picker you should be able to do the following:

    <img src="@(Model.Value<IPublishedContent>("ArticleImage").Url)" />
    

    This would get you the raw Url for the selected media it.

    However, this could error if the media was later deleted. A more robust approach would be:

     @{
           var articleImage = Model.Value<IPublishedContent>("ArticleImage");
           if(articleImage != null)
           {
                  <img src="@articleImage.Url" />
           }
     }
    

    You alsomight want to consider using ImageProcessor to render a specific crop of the uploaded image by using .GetCropUrl("cropAlias") instead, where cropAlias is the alias of a pre-defined crop of the dimensions you require.

    If you aren't using a media picker for this property type, let us know and we can try and help further :-)

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft