Left navigation and stylesheets

Kevin Deckard's Avatar

Kevin Deckard

13 Aug, 2014 08:59 PM

Hello! First time user here.
I have been given the responsibility of migrating my groups site to Cascade server. Yay! Unfortunately I have basically 0 experience with Velocity. It's not entirely foreign to me as I can understand the basics but I'm stuck at the moment.

We have been given a template that allows us to display a left navigation menu but currently it will only display children and subchildren in the menu when I need it to display more than that. I think the main problem is not knowing what to call the children of subchildren.

Below is an excerpt from our current page stylesheet. I believe the problem is not going deep enough into the folders but I'm not sure how to go deeper. Any hints or tips you could provide would be much appreciated.

<div id="left-nav">
            <ul class="menu">
                <li class="expanded first last active-trail">
                    
                    ## Section title
                    <a href="$rootPagePath">$sectionTitle</a>
                    
                    ## Arrow
                    <span class="arrow-down" style="position: absolute;border-top: 20px solid #f1f1f1;margin-top: -20px;"></span>
                    <span class="arrow-down"></span>
                    
                    ## Children
                    <ul class="menu">
                    
                        ## loop through each asset in the index block for this section
                        #foreach($child in $leftNav.children)
                            
                            ## $_PropertyTool.outputProperties($child)
                            
                            ## if there's a non-index page under this folder include it in the navigation
                            #if($child.name == "system-page" && $child.getChild("name").value != "index")
                                <li>$child.getChild("title").value.replaceAll("&amp;","&").replaceAll("&","&amp;")</li>
                            #end
                            
                            ## if it's a folder check to see if the children are folders or not
                            #if($child.name == "system-folder")
                                
                                #set($current = "false")
                                #set($current = $_XPathTool.selectSingleNode($child, "system-folder[@current='true']"))
                                #set($showInNav = "No")
                                #set($showInNav = $_XPathTool.selectSingleNode($child, "system-page[name='index']/dynamic-metadata[name='includeNavigation']/value").value)
                                #set($indexTitle = "---NEEDS TITLE---")
                                #set($indexTitle = $_XPathTool.selectSingleNode($child, "system-page[name='index']/title").value.replaceAll("&amp;","&").replaceAll("&","&amp;"))
                                #set($indexPath = "#")
                                #set($indexPath = $_XPathTool.selectSingleNode($child, "system-page[name='index']/path").value)
                                
                                #if($showInNav == "Yes")
                                
                                    ## check if current folder
                                    #if($current != "false")
                                        <li class="expanded active-trail">
                                            <a href="$indexPath">$indexTitle</a>
                                            <ul class="menu">
                                                ## loop through and find the sub-children
                                                #foreach($subchild in $child.children)
                                                    
                                                    #if($subchild.name == "system-folder")
                                                        #if($_XPathTool.selectSingleNode($subchild, "system-page[@current]"))
                                                            #set($active = "active")
                                                        #else
                                                            #set($active = "")
                                                        #end
                                                        
                                                        ## Show in left nav?
                                                        #set($showInNav = "No")
                                                        #set($showInNav = $_XPathTool.selectSingleNode($subchild, "system-page[name='index']/dynamic-metadata[name='includeNavigation']/value").value)
                                                        #set($indexTitle = "---NEEDS TITLE---")
                                                        #set($indexTitle = $_XPathTool.selectSingleNode($subchild, "system-page[name='index']/title").value.replaceAll("&amp;","&").replaceAll("&","&amp;"))
                                                        #set($indexPath = "#")
                                                        #set($indexPath = $_XPathTool.selectSingleNode($subchild, "system-page[name='index']/path").value)
                                                        #if($showInNav == "Yes")
                                                            <li class="leaf $active"><a href="$indexPath">$indexTitle</a></li>
                                                        #end
                                                    #end
                                                #end
                                            </ul>
                                        </li>
                                    #else
                                        #set($children = "")
                                        #if($_XPathTool.selectSingleNode($child, "system-page[@current]"))
                                            #set($expanded = "expanded")
                                            #set($children = $_XPathTool.selectNodes($child, "../system-folder[@current]/system-folder"))
                                        #else
                                            #set($expanded = "")
                                        #end
                                        <li class="$expanded"><a href="$indexPath">$indexTitle</a>
                                        #if($children != "")
                                            #foreach($currentChild in $children)
                                            
                                                ## Show in left nav?
                                                #set($showInNav = "No")
                                                #set($showInNav = $_XPathTool.selectSingleNode($currentChild, "system-page[name='index']/dynamic-metadata[name='includeNavigation']/value").value)
                                                #set($indexTitle = "---NEEDS TITLE---")
                                                #set($indexTitle = $_XPathTool.selectSingleNode($currentChild, "system-page[name='index']/title").value.replaceAll("&amp;","&").replaceAll("&","&amp;"))
                                                #set($indexPath = "#")
                                                #set($indexPath = $_XPathTool.selectSingleNode($currentChild, "system-page[name='index']/path").value)
                                                #if($showInNav == "Yes")
                                                    <li class="leaf"><a href="$indexPath">$indexTitle</a></li>
                                                #end
                                            #end
                                        #end
                                        
                                        
                                        </li>
                                    #end
                                    
                                #end
  1. 1 Posted by Ryan Griffith on 14 Aug, 2014 12:22 PM

    Ryan Griffith's Avatar

    Hi Kevin,

    Looking over your Format, it appears you are pretty much stuck since you're dealing with nested loops. Basically, for every level you would need to nest one more loop.

    I highly recommend going the recursive route using macros, because it would be much more flexible and more maintainable going forward. To get you started, we have a sample navigation Velocity Format that does just this.

    Please let me know if you have any questions.

    Thanks!

  2. Ryan Griffith closed this discussion on 20 Aug, 2014 02:39 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