Copied to clipboard

Flag this post as spam?

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


  • rendervouz 6 posts 126 karma points
    Sep 14, 2016 @ 06:42
    rendervouz
    0

    Check if a certain node is the descendants of a node

    Is there any way to check whether a node is a descendants of a certain node?

    I'd like to check with this code. But it doesnt work

    @if(CurrentPage.IsAncestorsOrSelf(1122)) {
        Html.RenderPartial("Submenu/About");
    }
    

    Is there any other way to do this? Thanks!

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Sep 14, 2016 @ 07:10
    Dennis Adolfi
    100

    Hi rendervouz.

    You are very close, try this example:

    @if (Umbraco.Content(1122).IsAncestorOrSelf(CurrentPage))
    {
        @Html.RenderPartial("Submenu/About")
    }
    

    Or, you can reverse the logic, by doing:

    @if (CurrentPage.IsDescendantOrSelf(Umbraco.Content(1122)))
    {
       @Html.RenderPartial("Submenu/About")
    }
    

    Best of luck to you! Take care!

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 14, 2016 @ 07:14
    Dennis Aaen
    0

    Hi Rendervouz.

    I think they reason why is not working for is because it should be:

    @if(CurrentPage.IsAncestorOrSelf(1122)) {
        Html.RenderPartial("Submenu/About");
    }
    

    So the different here is IsAncestorOrSelf and not IsAncestorsOrSelf You have these options

    .IsAncestor(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
    .IsAncestorOrSelf(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
    
    .IsDescendant(DynamicPublishedContent,valueIfTrue[,valueIfFalse])
    .IsDescendantOrSelf(DynamicPublishedContent,valueIfTrue[,valueIfFalse]
    

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft