Terminating foreach
I've hit a wall with something. I'm working on a faculty listing page which links out to the individual pages. There ate data definition values for Professor, Associate and Assistant Professor.
I started out with Professor and it works fine. When I replicated the x-path and foreach script for the other two, they don't display.
To test the x-paths, I substituted the Assistant and Associate values for the Professor and both display. It's when I put them in order int the script, Professor, Associate, and Assistant Professors that the trailing two don't display. It's as though I'm not terminating the foreach properly. I note that when I remove the setting of values to null (#set ($fname = "", etc) the last value for professor is repeated in the Associate listing. The script is attached. Any idea where I've gone amiss?
- script.txt 3.9 KB
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Charlie Holder on 29 Aug, 2011 02:13 PM
Can you post some sample XML?
Feel free to make the thread private if it's going to contain names, email addresses, etc.
3 Posted by steelej on 29 Aug, 2011 02:16 PM
A sample is attached, thanks.
Support Staff 4 Posted by Charlie Holder on 29 Aug, 2011 02:41 PM
The most glaring issue I see is that you're continuing to reference $prof inside your Associates and Assistants loops. The first thing I would do is switch $prof to $assop and $assp respectively.
I want to take a minute to talk about some things you're doing with Velocity -- maybe share some advice and knowledge for a quick minute. I will post those things I'd like to share on my next comment here in a few minutes. I am still putting them together, but wanted to go ahead and let you know what I think the issue is.
5 Posted by steelej on 29 Aug, 2011 02:53 PM
Yep, I'd say that's pretty glaring. I corrected it and it works. I knew it was something simple I was overlooking--just didn't think there was that much blindness involved. Pretty sloppy on my part.
I'll be happy to hear your instruction on Velocity.
Support Staff 6 Posted by Charlie Holder on 29 Aug, 2011 03:10 PM
I see that for some fields you're using the
.valueproperty and for some you're using the$_SerializerTool, which is fine. I want to suggest that you reverse the times you choose to using those two options.When you're working with a field that a user can type in information for (text input, textarea, WYSIWYG) I would use the
$_SerializerToolthen. I may be incorrect since I can't see your Data Definition, but some examples of this are your $chfname, $chlname, and $chphone.The
.valueproperty can safely be used when you know the output doesn't contain special chars, like a/pathor/linksince asset names after safe-guarded by Cascade. There really isn't any need to.serialize()those values.It looks like each one of your loops are pretty much exactly the same. I would suggest using a Macro to write that HTML for you. Basically writing a function to write the foreach loops for you and simply passing in the list you'd like available for the loop.
Here's an example using your code (not tested):
And then in the body of your code you can do this:
I would also look into Quiet Notation for times when you encounter an optional field that might be blank and you're using an if statement to make sure it's not empty.
I hope this information helps.
7 Posted by steelej on 29 Aug, 2011 03:31 PM
Charlie,
Thank you for taking time to do this. As things are, circumstances as they are, I'm much more pushed to make things work than to learn to do them more efficiently or elegantly.
Examples like these help me a good deal.
Jim
steelej closed this discussion on 29 Aug, 2011 03:31 PM.