Copied to clipboard

Flag this post as spam?

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


  • Tony Lorentzen 85 posts 174 karma points
    Mar 26, 2019 @ 14:38
    Tony Lorentzen
    0

    Am I daft or...

    I'm doing this to get all the descendants of type "hotelOffer" on my Umbraco 8 website:

    Umbraco.ContentAtRoot().First().Descendants("hotelOffer")

    Problem is I'm only getting one node; the front-page of the website, which isn't even of the type "hotelOffer". What's going on?

    kthxbye!

  • Rhys Hamilton 140 posts 942 karma points
    Mar 26, 2019 @ 16:17
    Rhys Hamilton
    101

    In V8, the Descendants() method gets the descendants by culture. As such, since there's no "culture" called hotelOffer, the results will be incorrect.

    Instead, you could use DescendantsOfType(), which accepts a contentType and a culture (if required).

    The following code should work:

     Umbraco.ContentAtRoot().First().DescendantsOfType("hotelOffer")
    
  • Tony Lorentzen 85 posts 174 karma points
    Mar 27, 2019 @ 23:30
    Tony Lorentzen
    1

    Hey Rhys - that sure did the trick. Where can I see changes like this without having to dig through every method whenever I'm trying to reuse old code? Thanks for the help!

  • Rhys Hamilton 140 posts 942 karma points
    Mar 28, 2019 @ 10:27
    Rhys Hamilton
    0

    I'm glad that worked for you!

    Whilst it might not be the best solution, generally I've been doing the following to re-factor old code for use in V8:

    • Looking through the documentation (not 100% updated)
    • Using the intellisense within Visual Studio to view parameters
    • Viewing the V8 source on GitHub (pulling it down locally makes debugging easier, so I'd recommend that).

    Admittedly, I'm still getting used to things, but that's what's been working for me at the moment. It's not a super-quick way of doing things, but hopefully it's of some use to others.

  • Tony Lorentzen 85 posts 174 karma points
    Mar 28, 2019 @ 14:23
    Tony Lorentzen
    1

    Yeah, obviously using intellisense within Visual Studio is the best way when the documentation is so incomplete. Also a good idea to have the V8 Source on hand when in doubt. I just really wish there was a complete documentation overview of what's changed from v7 to v8, but I guess nobody has that complete overview in a sharable format ;-)

    I just had a look at the docs for the IPublishedContent Collections and I've been unable to find anything about the DescendantsOfType.

    enter image description here

    Thanks again, Rhys - you're a legend!

Please Sign in or register to post replies

Write your reply to:

Draft