Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Sep 11, 2014 @ 22:03
    Amir Khan
    0

    Check if ancestor of node by id

    Hi, I've found this which seems to be checking if the current node is the ancestor or self, but it always returns false...I'm basically looking for the equivalent of "$currentPage/ancestor-or-self::node/@id = 2880" XSLT.

    Any ideas?
    Amir

    if(CurrentPage.IsAncestorOrSelf(2880)) {
    <h1>true</h1>
    } else {
    <h1>false</h1>
    }
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 11, 2014 @ 22:12
    Jeavon Leopold
    101

    Try this:

    if(CurrentPage.IsAncestorOrSelf(Umbraco.Content(2880))) {
         <h1>true</h1>
        } else {
           <h1>false</h1>
        }
    
  • Amir Khan 1287 posts 2744 karma points
    Sep 15, 2014 @ 16:37
    Amir Khan
    0

    Perfect, thanks Jeavon!

  • Amir Khan 1287 posts 2744 karma points
    Sep 15, 2014 @ 17:00
    Amir Khan
    0

    Actually, it looks like this returns false on any subpages?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 15, 2014 @ 17:55
    Ismail Mayat
    0

    Amir, Jeavon,

    Would it not just be easier just todo Umbraco.Content(2880).Path.Contains(CurrentPage.Id) ?? Btw Amir loved your last fight ;-} Sorry could not help myself there!

    Regards

    Ismail

  • Amir Khan 1287 posts 2744 karma points
    Sep 15, 2014 @ 17:59
    Amir Khan
    0

    Hi Ismail!

    Is anyone of those more efficient than the other? I'm just trying to switch things around based on the parent page for a 2 site installation, here's what actually ended up working for me, Ancestor only worked on the homapge, but no subpages. I'm not sure why that behavior is different than it was in the past.

    if(CurrentPage.IsDescendantOrSelf(Umbraco.Content(2880))) {
    <h1>true</h1>
    } else {
    <h1>false</h1>
    }
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 15, 2014 @ 20:13
    Jeavon Leopold
    0

    @Amir that is correct, if you think about it.

    @Ismail That's pretty much what it's doing but remember "1023" is contained in "11023" :)

Please Sign in or register to post replies

Write your reply to:

Draft