using dynamic metadata to set a link class with folder based navigation
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> </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.
http://help.hannonhill.com/discussions/velocity-formats/115-setting...
Sample folder index xml:
<system-page id="6e3d4ff6ac1009d000cf095ec711cba1">
<name>conditions</name>
<is-published>true</is-published>
<last-published-on>1434402428944</last-published-on>
<last-published-by>lfraser</last-published-by>
<title>Conditions</title>
<path>/specialties/allergy-immunology/conditions</path>
<site>1.citizensmemorial.com</site>
<link>site://1.citizensmemorial.com/specialties/allergy-immunology/conditions</link>
<created-by>lfraser</created-by>
<created-on>1432073621494</created-on>
<last-modified-by>lfraser</last-modified-by>
<last-modified>1432165881006</last-modified>
<dynamic-metadata>
<name>class</name>
<value>p2</value>
</dynamic-metadata>
Sample output with current format:
<ul class="mobile-menu">
<li class="p1">
<b></b>
<a href="[system-asset]site://1.citizensmemorial.com/specialties/allergy-immunology/clinical-programs[/system-asset]">Clinical Programs</a>
</li>
<li class="p1">
<b></b>
<a href="[system-asset]site://1.citizensmemorial.com/specialties/allergy-immunology/conditions[/system-asset]">Conditions</a>
</li>
<li class="p1">
<b></b>
<a href="[system-asset]site://1.citizensmemorial.com/specialties/allergy-immunology/patient-resources[/system-asset]">Patient Resources</a>
</li>
<li class="p1">
<b></b>
<a href="[system-asset]site://1.citizensmemorial.com/specialties/allergy-immunology/providers[/system-asset]">Providers</a>
</li>
Thanks in advance for the help.
Lauren
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 16 Jun, 2015 01:14 PM
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:
Please let me know if you have any questions.
Thanks!
2 Posted by lauren.fraser on 16 Jun, 2015 09:24 PM
Ryan,
That did the trick. Thanks!
Lauren
3 Posted by Ryan Griffith on 17 Jun, 2015 11:50 AM
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!
Ryan Griffith closed this discussion on 17 Jun, 2015 11:50 AM.