multi-select foreach
Here's my code and it works fine except when a staff member has 2 dept values - it only uses 1...
#set ($pages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page"))
#set ($depts = ['Application Support and Operations','Audio Visual and Video Conferencing','Business and Academic Solutions','Business Operations','Client Support Services','Clinical Informatics','Digital Media Production','Enterprise Systems and Infrastructure Services','Healthcare Security','Information Management','Information Security','Information Technology Support','Infrastructure and Collaboration Services','Innovation Zone (IZone)','Network Services','OIIT Leadership','Project Management','Software Development and Integration','Strategic Support Services','Technology Training','Telecommunications','Visual Interaction Design','Web Development'])
#foreach ($dept in $depts)
$dept
#foreach ($page in $pages)
#set ($dname = $_XPathTool.selectSingleNode($page, "dynamic-metadata[name = 'department']/value"))
#set ($path = $page.getChild("path").value)
##
#if($dname.value == $dept)
#if(!$path.contains("base-assets"))
$page.getChild("name").value
#end
#end
#end
#end
How do I have the staff member show up under every dept he's a part of?
thanks as always!!
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 29 Apr, 2016 08:27 PM
Hi Nando,
What you can do is tweak your code slightly so you can use XPath to filter all pages that have a department that matches the current one within the loop. When you have a moment, give the following a try for starters:
Please let me know if you have any questions.
Thanks!
2 Posted by Nando on 29 Apr, 2016 08:51 PM
That just gave me all the Departments...
The code above was used when i was hiding/showing full departments - I moved to hiding/showing staff members based on their dept now (sorry!).
but I would still like to know how to do it bc I'll need it for something else...
thanks again!
3 Posted by Ryan Griffith on 29 Apr, 2016 08:54 PM
By apologies, Nando, there was a typo in my proposed code. When you have a moment, please adjust the following line:
to:
Please let me know if you have any questions.
Thanks!
4 Posted by Nando on 29 Apr, 2016 09:01 PM
thats beautiful :) thanks!!
regarding my changes, would you mind having a look and giving me your thoughts
5 Posted by Ryan Griffith on 02 May, 2016 12:54 PM
Hi Nando,
In general, it looks like you are on the right track. I made a few tweaks to your format:
Please let me know if you have any questions.
Thanks!
6 Posted by Nando on 02 May, 2016 01:01 PM
Def looks cleaner but I'm getting this error:
7 Posted by Ryan Griffith on 02 May, 2016 01:10 PM
My apologies, Nando. When you have a moment, try changing line 28 to the following:
Please let me know if you have any questions.
Thanks!
8 Posted by Nando on 02 May, 2016 01:17 PM
that was it, saw it after I posted - thanks!
that macro is still giving me trouble in the divs below:
the dept names aren't being "sanitized " - they're outputting like this:
9 Posted by Ryan Griffith on 02 May, 2016 01:29 PM
Thank you for following up, Nando.
Let's try the following and let me know how it works out:
If that doesn't work, try replacing the single line with multiple:
Also, when outputting
${deptsClassName}
, let's do${deptsClassName.trim()}
do remove extra whitespace.As a side note: you may want to rethinking outputting the path of the as a class name because I am pretty sure slashes are not valid for that attribute. Perhaps you can use a
data-
attribute, or replace all slashes with hyphens.Please let me know if you have any questions.
Thanks!
10 Posted by Nando on 02 May, 2016 01:44 PM
path was just there temp - took it out.
this worked! thanks
Can you actually explain whats happening here ^^ I know the macro is sanitizing the dept name but how are you setting a variable with the same variable...
Also, you were wrapping the staff divs in the dept foreach which we didnt need anymore plus that would just duplicate staff members but its so much cleaner now, thanks to you! this is my code now:
11 Posted by Ryan Griffith on 02 May, 2016 03:37 PM
Thank you for following up, Nando. Glad to hear the latest change did the trick.
We're just doing some simple Velocity string concatenation here, by setting the variable's value to it's current value PLUS the output of the macro.
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 02 May, 2016 03:37 PM.