trying to pull in navigation for current page's siblings

roryreiff's Avatar

roryreiff

28 Aug, 2012 11:47 PM

Hello,

I am attempting to pull in the current pages siblings via the code below. Any idea what is not working about this? From what I can tell, this should work just fine! I have my index block set to 'append calling page data' and 'Start at the current page with folder hierarchy, siblings, and also render forward'

#set ( $folder = $_XPathTool.selectSingleNode($contentRoot, "//system-folder[system-page[@current]]" ) )
#set ( $links = $_XPathTool.selectNodes($folder, "system-page | system-symlink" ) )

<div class="pane pane-1 content-links">
    <ul>
    #foreach ($link in $links)
        #if ( !$link.getAttribute("current") )
            #set ( $path = $link.getChild('path').value )
            #if ( $link.name == 'system-symlink' )
                #set ( $path = $link.getChild('link').value )
            #end
            #set ( $displayName = $link.getChild('display-name').value )
            <li><a href="$path">$displayName</a></li>
        #end    
    #end
    </ul>
</div>
  1. 1 Posted by Ryan Griffith on 29 Aug, 2012 04:02 PM

    Ryan Griffith's Avatar

    Hi roryreiff,

    I suspect that the $folder variable may not be returning what you are expecting, this is especially true if the page you are viewing is at the root level because there is no folder at that point. Keeping your Index Block the same, let's try the following:

    #set ( $currentPage = $_XPathTool.selectSingleNode($contentRoot, "//system-page[@current]" ) )
    #set ( $links = $_XPathTool.selectNodes($currentPage, "../system-page | ../system-symlink" ) )
    
    <div class="pane pane-1 content-links">
        <ul>
        #foreach ($link in $links)
            #if ( !$link.getAttribute("current") )
                #set ( $path = $link.getChild('path').value )
                #if ( $link.name == 'system-symlink' )
                    #set ( $path = $link.getChild('link').value )
                #end
                #set ( $displayName = $link.getChild('display-name').value )
                <li><a href="$path">$displayName</a></li>
            #end    
        #end
        </ul>
    </div>
    

    What I am doing is obtaining the current page with //system-page[@current='true'] and selecting the system-page and system-symlink assets at the same level as the current page ../system-page | ../system-symlink.

    You should be able to remove the Append calling page data option on the Index Block if you would like to reduce the size of the Index Block a bit.

  2. 2 Posted by roryreiff on 29 Aug, 2012 06:53 PM

    roryreiff's Avatar

    Thanks Ryan, it works beautifully! Appreciate the fast response.

  3. 3 Posted by Ryan Griffith on 30 Aug, 2012 01:13 PM

    Ryan Griffith's Avatar

    THat's good news, glad to hear we got it working.

    Have a good one!

  4. Ryan Griffith closed this discussion on 30 Aug, 2012 01:13 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac