Copied to clipboard

Flag this post as spam?

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


  • Alex 1 post 71 karma points
    Oct 04, 2016 @ 13:52
    Alex
    0

    Show node 1 below root in ancestors

    Hi,

    I'm pretty new to this so apologies if this is a stupid question.

    I'm trying to show a link to whatever node is an ancestor of the current page immediately below the root. This could be the current page if it is immediately below the root.

    E.g.

    Home - Section 1 - Page 1 - Page 2 - Subpage 99 - Section 2 - Page 3 - Page 4

    If I'm on either "Section 1", "Page 1", "Subpage 99" or "Page 2" the link would show 'Section 1".

    I've read many forum posts and am tearing my hair out. I don't understand why I can't find the answer!

    Any help gratefully received.

    Thank you

  • Dennis Adolfi 1082 posts 6450 karma points MVP 7x c-trib
    Oct 05, 2016 @ 08:40
    Dennis Adolfi
    1

    Hi Alex.

    I think what you are looking for is the AncestorOrSelf(int: maxLevel) method. The int parameter specifies what level ancestor of the current node you want, where 1 is the root node. In your case, you´d want to specify 2 since you dont want the root node, but instead the 2 level node ancestor from the current node.

    Strong type example:

    @Model.Content.AncestorOrSelf(2)
    

    Dynamic example:

    @CurrentPage.AncestorOrSelf(2)
    

    Or:

    If I have misunderstood you , and you mean that you ALWAYS want to show the first child of the root node ("Section 1"), no matter where you are on the website, then this is what you want.

    Strong type example:

    @Model.Content.Site().FirstChild()
    

    Dynamic example:

    @CurrentPage.Site().FirstChild()
    

    Hope this was helpful!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies