Copied to clipboard

Flag this post as spam?

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


  • Mikael Axel Kleinwort 142 posts 487 karma points c-trib
    Feb 01, 2020 @ 14:39
    Mikael Axel Kleinwort
    0

    Traversing extentsion methods are missing from Umbraco.Core.Models.IPublishedContent

    According to the v8 documentation here, there should be these extension methods available on Umbraco.Core.Models.IPublishedContent:

    Children() // this is the same as using the Children property on the content item.
    Ancestors()
    Ancestors(int level)
    Ancestors(string nodeTypeAlias)
    AncestorsOrSelf()
    AncestorsOrSelf(int level)
    AncestorsOrSelf(string nodeTypeAlias)
    Descendants()
    Descendants(int level)
    Descendants(string nodeTypeAlias)
    DescendantsOrSelf()
    DescendantsOrSelf(int level)
    DescendantsOrSelf(string nodeTypeAlias)
    Siblings()
    SiblingsAndSelf()
    
    Ancestor()
    AncestorOrSelf()
    AncestorOrSelf(int level)
    AncestorOrSelf(string nodeTypeAlias)
    AncestorOrSelf(Func<IPublishedContent, bool> func)
    

    However, in my Umbraco 8.5.3 project, IPublishedContent items are missing all of these extension methods. All I see is .Children and .Parent

    Also I checked the API documentation, and there, the above stated extension methods are not documented as well.

    Is the documentation wrong (meaning, these extension methods have been removed), or is there something funny with my project?

  • Malthe Petersen 68 posts 383 karma points c-trib
    Feb 01, 2020 @ 16:19
    Malthe Petersen
    100

    Because they are extensions you need to be using the namespace in the top of your class. If you are in a .cshtml file you need to add @ before using: https://stackoverflow.com/questions/3239006/how-do-i-import-a-namespace-in-razor-view-page

    The namespace should be Umbraco.Web.PublishedContentExtensions: https://github.com/umbraco/Umbraco-CMS/blob/eed94d8cd03b04385c244a8f593e01e95f349218/src/Umbraco.Web/PublishedContentExtensions.cs So you need to have Umbraco.Web installed and referenced to be able to use these extensions.

    Hope this helps a little bit. :-)

  • Mikael Axel Kleinwort 142 posts 487 karma points c-trib
    Feb 01, 2020 @ 16:44
    Mikael Axel Kleinwort
    0

    @Malthe: great, thank you! I was missing

    using Umbraco.Web;

    as simple as that..... embarrassing! :-)

  • Malthe Petersen 68 posts 383 karma points c-trib
    Feb 01, 2020 @ 20:49
    Malthe Petersen
    0

    Glad I could help. Sometimes the simplest solution is the hardest. :-)

Please Sign in or register to post replies

Write your reply to:

Draft