Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

Query number of foreach matches?

Hi all,

Just bought CD this week and I'm in the progress of migrating my 2500+ pages website into CD (600 down, only 1900 to go...).

Is it possible to query the number of matches of a foreach loop and conditionally use code based on the results?

i.e. if a certain foreach loop returns 4 matches, insert <b>Four!</b>

Seven matches : <b>Seven!</b>



B4 CD I used to build and manage my website using a combination of m4, grep, find, sed, cp, mv, vi, etc... combined with a bunch of self written shellscripts, so I'm used to a 'pretty much anything can be done'-mindset.

Coming from UNIX (AIX, Solaris, Linux, and Mac OSX at home) makes my perspective of CD somewhat different than most users, I guess, (eventhough I have used Windows since v1.1).
What strikes me the most is the lack of possibilities to manipulate the data, the set variables and temporary variables. I am searching through the docs with 'there HAS to be more than this' on my mind, but it seems there isn't (yet?).

It all seems too simple, too limited..., and yet, I did not even encounter that much that I couldn't do in CD.

I think I'm in love.

Hey Joel, do an OSX version! (please?)


Saturday, June 5, 2004

This is an article counter that does numbers (7 rahth than seven for example). This one count all the articles in a site. Adjust the foreach conditions to suit your counting needs.

<script language="javascript" type="text/javascript">
var tmp = "{$ foreach x in (all) $}.{$ next $}";
if (tmp.length==0)
document.write(" currently no articles on this site.<br>");
} else
document.write("currently ",tmp.length," articles on this site.<br>");

Saturday, June 5, 2004

P.S. I copied the script so it doesn't contain my spelling errors.

Saturday, June 5, 2004

Thanks! I would not have figured that out by myself that way.


Sunday, June 6, 2004

I didn't think of it either. Thanks go to Joel G.

Sunday, June 6, 2004

*  Recent Topics

*  Fog Creek Home