Copied to clipboard

Flag this post as spam?

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


  • Sandro 45 posts 118 karma points c-trib
    Aug 21, 2009 @ 17:06
    Sandro
    0

    How to get the parent node name on a specific level from current page

    I can get the parent node name on a specific level by using

    $currentPage/ancestor::node [@level=1]/node/@nodeName

    But this gets all the nodes on this level. Is there an elegant way to select just the "level 1 parent" of $currentPage?

  • Chris Koiak 700 posts 2626 karma points
    Aug 21, 2009 @ 17:12
    Chris Koiak
    100

    Your xslt gets the names of the children of the level 1 node. Not the name of the level 1 node.

    try

    $currentPage/ancestor::node [@level=1]/@nodeName
  • Sandro 45 posts 118 karma points c-trib
    Aug 21, 2009 @ 17:22
    Sandro
    0

    ah... that's it! Time to knock off work :)

  • Tom Cowling 144 posts 343 karma points
    Jul 28, 2010 @ 16:51
    Tom Cowling
    0

    Sorry to bump this thread after 11 months, but I found it really useful!

    But following on from this, how could I turn this into a link to the level 1 node it's just found?

     

    Thanks,

     

    Tom

  • Dave 16 posts 36 karma points
    Jul 28, 2010 @ 21:07
    Dave
    0

    Depends slightly on the version your running?

    in 4.5 this works in my testing:

    <a href="{umbraco.library:NiceUrl($currentPage/ancestor::* [@level=1]/@id)}">
    <
    xsl:value-of select="$currentPage/ancestor::* [@level=1]/@nodeName"/></a>

    A word of caution:  Because NiceUrl is expecting an integer, you'll have to check the "Skip Testing" in order to save the XSLT. 

    I haven't learned how to avoid that yet!

     

  • Tom Cowling 144 posts 343 karma points
    Jul 29, 2010 @ 21:07
    Tom Cowling
    0

    Hi Dave,

     

    Thanks for that, but it's actually whatever the level 2 node it's sitting in that I want it to show.


    If I use your code and change the 1 to a 2, it comes up with:
    Error parsing XSLT file: \xslt\leftnav.xslt

    I'm using version: umbraco v 4.0.4.2 (Assembly version: 1.0.3811.17115), by the way..

    Can anyone help? :(

    Thanks,

    Tom

  • Connie DeCinko 931 posts 1160 karma points
    Jul 29, 2010 @ 23:13
    Connie DeCinko
    0

    In order to avoid the error, test for an empty value first.

  • 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