using dynamic metadata to set a link class with folder based navigation

lauren.fraser's Avatar


15 Jun, 2015 09:45 PM

We have a folder based velocity format to set the navigation for any pages in that sub-folder. I need to have a different link class for every page based on a dynamic metadata field. I've set a variable $pvalue and called in it my #foreach loop, but it is always showing as set to p1 ( instead of p2, p3, etc).

Here's my velocity code:

#set ($folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[name != 'index']"))
#set ($folderName = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/folder-name"))

<div class="nav-main"> <div class="main"> <div class="mobile-nav"><a class="mobile-toggle" href="javascript:void(0)"><img alt="menu-bg" src="[system-asset:id=d9974cd1ac1009d0007b451469cc3b57]/_common/images/page-layout/menu-small.png[/system-asset]" />Menu</a></div> <div class="navigation"> <ul class="mobile-menu"> #foreach ($folderPage in $folderPages) #set ($folderTitle = $folderPage.getChild("title")) #set ($folderPath = $folderPage.getChild("link").value) #set ($pValue = $_XPathTool.selectSingleNode($folderPages, "dynamic-metadata[name='class']/value").value) <li class="$pValue"><b>&#160;</b><a href="[system-asset]${folderPath}[/system-asset]">$_EscapeTool.xml($folderTitle.value)</a></li> #end <li></li> </ul> </div> </div> </div>

I found this older discussion that seems related, but our dynamic metadata field is a drop down, so there's always going to be a value. It mentions: "When working with loops, I almost always reset variables to an empty string or null on every iteration."
Is that what I would need to do in this case? I'm not sure how to reset a variable in a loop like this.

Sample folder index xml:

    <system-page id="6e3d4ff6ac1009d000cf095ec711cba1">

Sample output with current format:

 <ul class="mobile-menu">
                <li class="p1">
                    <a href="[system-asset]site://[/system-asset]">Clinical Programs</a>
                <li class="p1">
                    <a href="[system-asset]site://[/system-asset]">Conditions</a>
                <li class="p1">
                    <a href="[system-asset]site://[/system-asset]">Patient Resources</a>
                <li class="p1">
                    <a href="[system-asset]site://[/system-asset]">Providers</a>

Thanks in advance for the help.

  1. 1 Posted by Ryan Griffith on 16 Jun, 2015 01:14 PM

    Ryan Griffith's Avatar

    Hi Lauren,

    It looks like you are on the right track, but I noticed you may be using the incorrect context node when obtaining the value of the field. Specifically, you are using $folderPages instead of $folderPage, which I believe will always return the value from the first node.

    When you have a moment, try adjusting that line to the following and let me know how it works out:

    #set ($pValue = $_XPathTool.selectSingleNode($folderPage, "dynamic-metadata[name='class']/value").value)

    Please let me know if you have any questions.


  2. 2 Posted by lauren.fraser on 16 Jun, 2015 09:24 PM

    lauren.fraser's Avatar

    That did the trick. Thanks!

  3. 3 Posted by Ryan Griffith on 17 Jun, 2015 11:50 AM

    Ryan Griffith's Avatar

    Thank you for following up, Lauren, I am glad to hear the adjustment did the trick.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 17 Jun, 2015 11:50 AM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts


? 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


26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM