Fog Creek Software
Discussion Board




Knowledge Base
Documentation
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>

etc.etc.

---

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?)

Rogn

Rognvaldr
Saturday, June 05, 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">
//<![CDATA[
<!--
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>");
}
//-->//]]>
</script>

tk
Saturday, June 05, 2004

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

tk
Saturday, June 05, 2004

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

Rogn

Rognvaldr
Sunday, June 06, 2004

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

http://discuss.fogcreek.com/CityDesk/default.asp?cmd=show&ixPost=10401&ixReplies=1

tk
Sunday, June 06, 2004

*  Recent Topics

*  Fog Creek Home