Copied to clipboard

Flag this post as spam?

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


  • DS 21 posts 162 karma points
    Apr 27, 2016 @ 22:46
    DS
    0

    Render from 2nd document type in Nested Content

    I am unable to render anything from a 2nd document type in a NC.

    Everything renders fine for the first doc type using:

    var items = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("contentBlock"); 
    ...
    @item.GetPropertyValue("sectionHeading")
    

    How do you access the 2nd (or 3rd etc.) doc type that is a part of a NC?

    Thanks for any help!

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 28, 2016 @ 10:31
    Lee Kelleher
    0

    Hi Dustin,

    How are you setting the item variable?
    Do you have an extended code snippet that you could share?

    The items variable will contain a collection of the NC nodes, so should be easily looped over, like so:

    @foreach(var item in items)
    {
      <li>@item.GetPropertyValue("someAlias")</li>
    }
    

    Thanks,
    - Lee

  • DS 21 posts 162 karma points
    Apr 28, 2016 @ 15:25
    DS
    0

    Yes, sorry for not being clear enough with my ellipsis in my code sample, I am iterating with a foreach just like your code sample.

    I can access and render everything in the first nested doc type using that method just fine, but not the 2nd doc type. My 2nd doc type contains images as you can see below:

    foreach (var item in items)
    {
       <table>
           <tr>
           <td><img src="@Umbraco.Media(item, "staffImage1").Url" /></td>
           <td><img src="@Umbraco.Media(item, "staffImage2").Url" /></td>
           <td><img src="@Umbraco.Media(item, "staffImage3").Url" /></td>
           </tr>
           <tr>
           <td>@item.GetPropertyValue("bioLink1")</td>
           <td>@item.GetPropertyValue("bioLink2")</td>
           <td>@item.GetPropertyValue("bioLink3")</td>
           </tr>
       </table>
    }
    

    When I attempt to render the images like above, I get an error that "Parameter 'ID' must be a string or integer". When I try rendering like...

    <img src="@item.GetPropertyValue("staffImage1")" />
    

    I of course get an image placeholder.

    Thanks

  • DS 21 posts 162 karma points
    Apr 28, 2016 @ 21:21
    DS
    100

    After a lot of digging, I figured out what I needed:

    @Umbraco.Media(@item.GetPropertyValue("staffImage1")).Url
    

    Images are rendering just fine now.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 29, 2016 @ 08:49
    Lee Kelleher
    0

    Hi Dustin,

    Glad that you've got it working.

    I have a sneaky feeling that Nested Content and @Umbraco.Media calls (without the GetPropertyValue bit), don't play so nicely together. I've never tried it myself, but will make a note of it to look at in future.

    Cheers,
    - Lee

Please Sign in or register to post replies

Write your reply to:

Draft