Copied to clipboard

Flag this post as spam?

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


  • Bunnynut 136 posts 318 karma points
    Aug 19, 2019 @ 17:20
    Bunnynut
    0

    Unable to display image property of childnode

    Hi, on the homepage of my Umbraco v8 website I want to show a list of childnodes from a given parentnode, these items are jobopenings. Each of those childnodes have a property of the type Media. I am having a hard time displaying the image of the childnode.

    This is what I've tried so far:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
            var jobOpenings = Umbraco.Content(Guid.Parse("09fdad92-488c-474f-a8d9-77dfe5f4bd65"))
            .Children("jobopening")
            .Where(x => x.IsPublished())
            .Where(x => x.IsVisible())
            .Where(x => x.HasProperty("showOnHomepage"))
            .Where(x => (bool)x.GetProperty("showOnHomepage").Value())
            .OrderByDescending(x => x.CreateDate);
    }
    foreach (var jobOpening in jobOpenings)
    {
        //Title shows up
        @jobOpening .Value("title")
    
        //The following two lines both result in the text "Umbraco.Web.PublishedModels.Image"
        @jobOpening .GetProperty("image").GetValue();
        @jobOpening .Value("image");
    }
    

    What is the correct way to show the image?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 19, 2019 @ 18:56
    Nik
    0

    Hey Bunnynut,

    Okay so I would do something like this

    //This is using Models builder models by the way
    foreach(JobOpening jobOpening in jobOpenings) 
    {
         <h2> @jopOpening.Title</h2>
         if(jobOpening.Image != null)
         {
             <img src="@jobOpening.Image.Url"/> 
             //Alternatively use .GetCropUrl() instead of .Url and specify the crop to display
         }
    }
    

    Thanks,

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft