Incorrect path in submenus
Hi-
On one of our sites, the script sorting left menu is not
displaying the correct path link for inner folders- for example
here:
http://stage.aurora.edu/woodstock/academics/adult-degree-completion...#
The bottom -most link, AU and MCC partnership program test does not
append /index to the very end and hence throws an error within
cms(404)... Also, when you do get to the page, it is supposed to
bold the AU mcc part on same left nav as any other link, instead it
throws you out directly under adult degree completion programs and
rest of the left nav disappears.
Here is the left nav velocity script that I have been experimenting with-
#*
Authors: Jim Petkus, John Kocsis
Owner: Aurora University
Copyright: Aurora University
Function: Build Left Navigation Dynamically
Original Date: 1-19-2012
Last Modified: 1-29-2012
Version: 1.12.1.29
Please keep notes if you change anything, update version and dates as needed.
*#
#*
The #displaychildren($node) macro will check the passed $node to see if it matches the folder that we are currently in.
If true then this directory will displayed and checked for children to display.
If on the current page then then there are no more levels to dig through and it should be highlighted.
*#
#macro(displaychildren $node)
#set ($checkfolder = $node.getChild('path').value)
#set ($displaychildren = 0)
#set ($active = 0)
#if ($node.getAttribute('current').value == "true")
#set ($active = 1)
#end
#if ($node.name == "system-folder")
#foreach ($path in $currentpath)
#if ($path.getChild('name').value == $_StringTool.substringAfter($checkfolder, $level))
#set ($displaychildren = 1)
#set ($active = 1)
#end
#end
#end
#end
#*
The #linkorfile($node $arrow) macro will test the passed $node to see if it is a reference link (i.e. system-file or system-symlink).
If true then display the simlink or file in the left nav.
$arrow is used to tell which level the item is on and display the appropriate arrow.
2 = top level, 0 = 2nd levels, 1 = all other levels.
*#
#macro(linkorfile $node $arrow)
#if ($shownav == 1)
<li>
<a href="$node.getChild('path').value">
#if ($arrow == 2)
<div class="accnav_arrow_1">»</div>
$_SerializerTool.serialize($node.getChild('display-name'), true)
#elseif ($arrow == 1)
<div class="accnav_arrow_3">•</div>
<div class="lnav_name">$_SerializerTool.serialize($node.getChild('display-name'), true)</div>
#elseif ($arrow == 0)
<div class="accnav_arrow_2">»</div>
<div class="lnav_name">$_SerializerTool.serialize($node.getChild('display-name'), true)</div>
#end
</a>
</li>
#else
#set ($checknav = 1)
#end
#end
#*
The #program macro is called only when in the /aurora/academics/programs-majors/graduate or /aurora/academics/programs-majors/undergraduate
directories and will not display additional menus until a program or major has been selected. Then the program and submenu items will be
generated and displayed on the page.
*#
#macro(program)
#set ($program = $_XPathTool.selectSingleNode($contentRoot, "//system-folder[@current = 'true']"))
#if ($_StringTool.substringAfter($program.getChild('path').value, $level) != 'graduate-programs' && $_StringTool.substringAfter($program.getChild('path').value, $level) != 'adult-degree-completion-programs')
<li>
#set ($href = $program.getChild('path').value + "/index")
<a class="active" href="$href">
<div class="accnav_arrow_2">»</div>
<div class="lnav_name">$_SerializerTool.serialize($program.getChild('display-name'), true)</div>
</a>
<ul class="progmenu">
#foreach ($pitem in $program.children)
#if ( ($pitem.getAttribute('reference').value == "true" || $pitem.name == "system-symlink" || $pitem.name == "system-file") && $pitem.getChild('display-name') && $pitem.getChild('display-name').value != "" )
#linkorfile($pitem 1)
#else
#foreach ($pmeta in $pitem.children)
#if ($pmeta.getChild('name').value == 'left-nav' && $pmeta.getChild('value').value == 'Yes')
<li>
#if ($pitem.getAttribute('current').value == "true")
<a class="active" href="$pitem.getChild('path').value">
#else
<a href="$pitem.getChild('path').value">
#end
<div class="accnav_arrow_3">•</div>
<div class="lnav_name">$_SerializerTool.serialize($pitem.getChild('display-name'), true)</div>
</a>
</li>
#end
#end
#end
#end
</ul>
</li>
#end
#end
#*
The #recurse($node $indent $folder) is only called when $displaychildren = 1.
$node is the folder xpath that we need to loop through and display, as well
as check to see if there are further levels to loop through.
$indent is either 0 or 1 if we wish to indent or not.
(original setup is to indent only after the first itteration)
$folder is the folder to be checked against $level and to see if under programs-majors.
This macro will loop through the passed node looking for folders or pages which have been set
to display in the left nav and check to see if there are submenus to display based on the
current folder.
-- Caution --
This macro does call it self in recursive fashion in order to keeep building submenus,
if there are to many levels deep eventually the column width will be insufficient to
display all the submenus without overflow.
*#
#macro(recurse $node $indent $folder)
#foreach ($path in $currentpath)
#if ($path.getChild('name').value == $_StringTool.substringAfter($folder, $level))
#if ($indent == 0)
<ul class="menu">
#else
<ul class="submenu">
#end
#if ($folder == '/woodstock/academics/graduate-programs' || $folder == '/woodstock/academics/adult-degree-completion-programs')
#program()
#end
#if ($node.name == "system-folder")
#set ($level = $level + $path.getChild('name').value + "/")
#end
#foreach ($child in $node.children)
#if ( ($child.getAttribute('reference').value == "true" || $child.name == "system-symlink" || $child.name == "system-file") && $child.getChild('display-name') && $child.getChild('display-name').value != "" )
#linkorfile($child $indent)
#else
#foreach ($meta in $child.children)
#if ($meta.getChild('name').value == 'left-nav' && $meta.getChild('value').value == 'Yes')
#displaychildren($child)
<li>
#if ($child.name == "system-page")
#set ($href = $child.getChild('path').value)
#elseif ($child.name == "system-folder")
#set ($href = $child.getChild('path').value + "/index")
#end
#if ($active == 1)
<a class="active" href="$href">
#else
<a href="$href">
#end
#if ($indent == 0)
<div class="accnav_arrow_2">»</div>
#else
<div class="accnav_arrow_3">•</div>
#end
<div class="lnav_name">$_SerializerTool.serialize($child.getChild('display-name'), true)</div>
</a>
#if ($displaychildren == 1)
#recurse($child 1 $child.getChild('path').value)
#end
</li>
#end
#end
#end
#end
</ul>
#end
#end
#end
#*
This is the main part of the program that calls the macros above as needed.
We set the main xpath folders begining at the root level of the site and display first
the main level of the site. Folders and pages are located using the macros above to
build the submenu structure.
*#
#set ($currentpath = $_XPathTool.selectNodes($contentRoot, "/system-index-block/descendant::system-folder[descendant::system-page[@current = 'true']]"))
#set ($currentpage = $_XPathTool.selectSingleNode($contentRoot, "//system-page[@current = 'true']"))
#set ($rootmenu = $_XPathTool.selectSingleNode($contentRoot, "//system-folder[path='/woodstock']"))
#set ($level = "/woodstock/")
#set ($checknav = 0)
#set ($shownav = 0)
#foreach ($topmenu in $rootmenu.children)
##if ($topmenu.getChild('dynamic-metadata').getChild('name').value == 'top-nav' && $topmenu.getChild('dynamic-metadata').getChild('value').value == 'Yes')
#foreach ($path in $currentpath)
#if ($path.getChild('name').value == $_StringTool.substringAfter($topmenu.getChild('path').value, $level))
#if ($topmenu.name == "system-folder")
#set ($level = $level + $path.getChild('name').value + "/")
#end
#foreach ($leftmenu in $topmenu.children)
#if ( ($leftmenu.getAttribute('reference').value == "true" || $leftmenu.name == "system-symlink" || $leftmenu.name == "system-file") && $leftmenu.getChild('display-name') && $leftmenu.getChild('display-name').value != "" )
#linkorfile($leftmenu 2)
#else
#foreach ($meta in $leftmenu.children)
#if ($meta.getChild('name').value == 'left-nav' && $meta.getChild('value').value == 'Yes')
#set ($checknav = 1)
#end
#end
#end
#end
#if ($checknav == 1)
<nav class="subnav">
<ul class="lnav subnav-list" id="left_nav">
#set ($shownav = 1)
#end
#foreach ($leftmenu in $topmenu.children)
#if ( ($leftmenu.getAttribute('reference').value == "true" || $leftmenu.name == "system-symlink" || $leftmenu.name == "system-file") && $leftmenu.getChild('display-name') && $leftmenu.getChild('display-name').value != "" )
#linkorfile($leftmenu 2)
#else
#foreach ($meta in $leftmenu.children)
#if ($meta.getChild('name').value == 'left-nav' && $meta.getChild('value').value == 'Yes')
#displaychildren($leftmenu)
<li>
#if ($leftmenu.name == "system-page")
#set ($href = $leftmenu.getChild('path').value)
#else
#set ($href = $leftmenu.getChild('path').value + "/index")
#end
#if ($active == 1)
<a class="active" href="$href">
#else
<a href="$href">
#end
<div class="accnav_arrow_1">»</div>
$_SerializerTool.serialize($leftmenu.getChild('display-name'), true)
</a>
#if ($displaychildren == 1)
#recurse($leftmenu 0 $leftmenu.getChild('path').value)
#end
</li>
#end
#end
#end
#end
#if ($shownav == 1)
</ul>
</nav>
#end
#end
#end
##end
#end
I am a little lost at this point. Any help would be greatly appreciated. Thanks so much.
Shruti
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
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
1 Posted by Ryan Griffith on 23 Sep, 2015 02:43 PM
Hi Shruti,
When you have a moment, would you also be able to attach some sample XML so I can take a look at the Format in my local instance. The sample XML can be obtained by editing the Format and selecting the appropriate Block and Context page within the Preview Options section.
Thanks!
2 Posted by ssargam on 23 Sep, 2015 05:15 PM
Thanks, Ryan-
Please find the xml attached.
3 Posted by Ryan Griffith on 23 Sep, 2015 05:44 PM
Hi Shruti,
Unfortunately, it does not look like the attached file is valid XML. Did you by chance grab the XML provided in the top "preview" box, or the result of clicking the Test Format button?
Thanks!
4 Posted by ssargam on 23 Sep, 2015 05:53 PM
How about now?
5 Posted by ssargam on 23 Sep, 2015 05:53 PM
updated file attached
6 Posted by Ryan Griffith on 23 Sep, 2015 06:14 PM
Perfect, thank you Shruti.
Looking over your Format, I believe the problem is within your program macro. Specifically, all of the other macros have something like the following which is what is adding on that
/index
for folders.My initial thought is that you would want to do something similar here.
Please let me know if you have any questions.
Thanks!
7 Posted by ssargam on 23 Sep, 2015 08:15 PM
Hi Ryan-
That was my initial thought as well, and I did try this change in program macro #macro(program)
#set ($program = $_XPathTool.selectSingleNode($contentRoot, "//system-folder[@current = 'true']"))
#if ($_StringTool.substringAfter($program.getChild('path').value, $level) != 'graduate-programs' && $_StringTool.substringAfter($program.getChild('path').value, $level) != 'adult-degree-completion-programs')
<li>
#set ($href = $program.getChild('path').value + "/index")
<a class="active" href="$href">
<div class="accnav_arrow_2">»</div>
<div class="lnav_name">$_SerializerTool.serialize($program.getChild('display-name'), true)</div>
</a>
<ul class="progmenu">
#foreach ($pitem in $program.children)
#if ( ($pitem.getAttribute('reference').value == "true" || $pitem.name == "system-symlink" || $pitem.name == "system-file") && $pitem.getChild('display-name') && $pitem.getChild('display-name').value != "" )
#linkorfile($pitem 1)
#else
#foreach ($pmeta in $pitem.children)
#if ($pmeta.getChild('name').value == 'left-nav' && $pmeta.getChild('value').value == 'Yes')
<li>
#if ($pitem.name == "system-page")
#set ($href = $pitem.getChild('path').value)
#elseif ($pitem.name == "system-folder")
#set ($href = $pitem.getChild('path').value + "/index")
#end
#if ($pitem.getAttribute('current').value == "true")
<a class="active" href="$pitem.getChild('path').value">
#else
<a href="$pitem.getChild('path').value">
#end
<div class="accnav_arrow_3">•</div>
<div class="lnav_name">$_SerializerTool.serialize($pitem.getChild('display-name'), true)</div>
</a>
</li>
#end
#end
#end
#end
</ul>
</li>
#end
#end
This didn't change anything. Am I missing anything?
8 Posted by Ryan Griffith on 23 Sep, 2015 08:50 PM
Hi Shruti,
I am seeing the following in your macro:
Instead, try making the following change:
Please let me know if you have any questions.
Thanks!
9 Posted by ssargam on 23 Sep, 2015 08:58 PM
Great! That fixed one of the issues. I can get to the index page but the menu changes and the page out when you click on it, Like here: http://stage.aurora.edu/woodstock/academics/adult-degree-completion-programs/nursing/index.html
Thanks!
10 Posted by Ryan Griffith on 23 Sep, 2015 09:04 PM
Glad to hear the latest change resolved the
index
issue.To confirm, when you click on the sub-folder link, are you looking to continue to show the same navigation that you see when viewing the link you just provided? If so, it sounds like this may be due to one of two things:
Please let me know if you have any questions.
Thanks!
11 Posted by ssargam on 23 Sep, 2015 09:19 PM
The block is actually set at this- "Start at the current page with folder hierarchy, and also include siblings"
Is this to be changed?
Thanks!
12 Posted by Ryan Griffith on 23 Sep, 2015 09:28 PM
Hi Shruti,
Perhaps try using the Start at the current page with folder hierarchy, siblings, and also render forward option to see if it will include the children of the folder hierarchy. Also, make sure you have an appropriate value entered for the render depth option.
Let me know if this makes a difference. If not, you may need to select the base folder (or one of the parent folders) as the starting point and just include everything.
Please let me know if you have any questions.
Thanks!
13 Posted by ssargam on 23 Sep, 2015 09:48 PM
Okay, thanks, Ryan! Tried adding index folder an d all other options as well. Either everything disappears or it stays the same.
Is there anything that needs to be changed in the script?
14 Posted by Ryan Griffith on 23 Sep, 2015 09:57 PM
Hi Shruti,
My best guess is you would need to either tweak some XPath or the way the Format traverses the hierarchy.
Please let me know if you have any questions.
Thanks!
15 Posted by ssargam on 23 Sep, 2015 09:58 PM
Thanks, Ryan. I'll try a few things and see if it gets me anywhere.
Appreciate your help.
16 Posted by Ryan Griffith on 23 Sep, 2015 10:06 PM
Not a problem at all, Shruti. Definitely look into those couple of items and keep me posted on your progress or if you have any questions.
Thanks!
17 Posted by ssargam on 06 Oct, 2015 08:10 PM
Hi Ryan- I went backto the script and tried all different options for index folder but I am a little lost at the recurse macro. The menu that builds for sub folder is completely out of the main navigation. Like here: http://stage.aurora.edu/woodstock/academics/adult-degree-completion-programs/nursing/au-mcc-partnership-test/index.html#.VhQpFGuBxOJ
18 Posted by Ryan Griffith on 07 Oct, 2015 12:08 PM
Hi Shruti,
When you have a moment, please attach the following so I can help take a closer look:
Please let me know if you have any questions.
Thanks!
19 Posted by ssargam on 07 Oct, 2015 01:38 PM
Hi Ryan-
The files are attached for your reference> Thanks for the help, really appreciate it.
Shruti
20 Posted by Ryan Griffith on 08 Oct, 2015 01:19 PM
Thank you for attaching the files, Shruti.
Also, when you have a moment, please attach or paste the expected HTML markup for the menu so I can get a better sense of what you're looking for.
Thanks!
21 Posted by ssargam on 08 Oct, 2015 01:38 PM
Hi Ryan-
AU-mcc-partnership test is a folder under Nursing. If you look at this page- http://stage.aurora.edu/woodstock/academics/adult-degree-completion-programs/nursing/au-mcc-partnership.html
The last item on left nav is the folder, without the index added at the end. And when I click on it, I want it to be an active item and stay in same left nav, rather create a new one like it does now.
I have attached the expected markup of left nav.
Please let me know if this makes sense.
Thanks!
Shruti
22 Posted by Ryan Griffith on 08 Oct, 2015 06:56 PM
Hi Shruti,
I spent most of the morning dissecting the Format and, honestly, it's very difficult to follow. Specifically, if you debug the loops the context variable is a mixture of page/folder elements as well as metadata and system elements; also it's difficult to determine what some of the macros do in general.
That being said, I retooled one of our example Formats and I believe I was able to get the desired output. Note: you don't currently have child pages within that active folder so it's difficult to debug beyond that 3rd level, but I think it should work. Give the following a try for starters:
Please let me know if you have any questions.
Thanks!
23 Posted by ssargam on 08 Oct, 2015 08:15 PM
Thanks Ryan.
Those were pretty much my difficulties as well.
With current script, I can no longer see the AU mcc folder under nursing.
I'll tweak a few things here and see what I can get.
Thanks so much, Ryan!
24 Posted by Ryan Griffith on 08 Oct, 2015 08:45 PM
Not a problem at all, Shruti.
Are you referring to the
au-mcc-partnership-test
folder? If so, it's at the bottom of the nested menu. As I mentioned, your Index Block did not contain any pages within that folder so you won't see an additional menu under it.Please let me know if you have any questions and keep me posted on your findings.
Thanks!
25 Posted by ssargam on 08 Oct, 2015 08:55 PM
Okay.
So does that mean I need to change the rendering behavior on index block to a different option?
If so, other options did not display it either.
26 Posted by Ryan Griffith on 09 Oct, 2015 11:21 AM
Hi Shruti,
Can you confirm whether this folder contains additional pages besides
index
? The sample XML you provided did not, so my assumption is there are no other pages at this level in the menu to display.As I mentioned, once you create some more pages within that folder the submenu should appear.
Thanks!
27 Posted by ssargam on 09 Oct, 2015 02:10 PM
No. I meant the folder(AU MCC Partnership test) that was at the left nav bottom on this page here- http://stage.aurora.edu/woodstock/academics/adult-degree-completion-programs/nursing/index.html#.VhfHlSv3T6k
It no longer appears. Nursing itself has various pages under it, and they all show just fine(as you can see on the link above), AU MCC partnesrship Test is one and only folder under nursing, and that does not show anymore. :)
28 Posted by ssargam on 09 Oct, 2015 02:12 PM
Here is the xml as well.
29 Posted by Ryan Griffith on 09 Oct, 2015 05:31 PM
Hi Shruti,
Looks like you will need to tweak the XPath on line 65 where
showFolder
attempts to traverse it's children. Specifically, the XPath is only looking for folders that have the current page within it, which is why your folder isn't showing.Try the following and let me know how it works out:
Please let me know if you have any questions.
Thanks!
Ryan Griffith closed this discussion on 02 Nov, 2015 08:03 PM.
ssargam re-opened this discussion on 26 Oct, 2017 08:45 PM
30 Posted by ssargam on 26 Oct, 2017 08:45 PM
Hi Ryan-
I hope I am sending the email to the right person, I had posted a couple questions on formats forum but I haven't received much help, and you have always been able to fix things for us in past.
So, I dug into my older emails to find a way to email you.
This is where I posted my question- https://help.hannonhill.com/hc/en-us/community/posts/115001929934-Nested-loops?page=1#community_comment_115001293693
I am unable to loop through various images in mini slider, getting only first image for each section. Could you PLEASE take a look?
Thanks so much,
Shruti
--
Shruti Sargam
Digital Communications Manager
Aurora University
(630) 844-4233
ssargam @aurora.edu
Discover what matters. And build your life around it.
aurora.edu | facebook.com/aurorauniversity | twitter.com/aurorau