Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

foreachtwo loop instead of foreach loop?

I want to use the foreach loop with an iteration of two articles, since the two articles will have a different display.

For example, the first article teaser has a left alignment, the second a right alignment, the third article a left alignment again, ect (depending the amount of articles in the folder Articles)

pseudo code:
for ( x; x<folder(articles); x=+2)
{
    display x.teaser alignment "left"

    display x+1.teaser alignment "right"
}

Would this be possible within CityDesk.
How would the foreach loop (or different scripting code) look like?

Johan Koerts
Tuesday, December 03, 2002

I don't quite understand what you are trying to do.  I don't think you can build a script to do exactly what you want.  But, I think there may be another way to accomplish what you want.

tk
Tuesday, December 03, 2002

Sounds like he wants to process every other article in a loop, as opposed to each article.

I have thought of a need for this myself, maybe to fill out a table to create a two or three column list instead of having everything always provided as a straight single column list.

I don't think CityDesk can do this with its current scripting syntax.  Its a nice suggestion if it can be done.

Jeff Kolker
Tuesday, December 03, 2002

fo now I have solved the problem as follow:

{$ foreach x (folder "Articles") $}
{if nonblank x.keywords}
  <table>..... x.teaser .....</table>
{$endif$}
{if blank x.keywords}
  <table>..... x.teaser .....</table>
{$endif$}
{$next$}

Depending the field keywords I can determine which table to use for displaying the teaser of the article.

But to accomplish this I need to misuse the field keywords. As a programmer I hate these kind of "work-arounds". I guess programmers of FogCreek would understand.

Another solution than the "foreachtwo", would be a regular if statement, validating context (=articles) sensitive variables. Something like: {$ if x.var="true" $}....{$endif$}
I guess this has been suggested before.

Johan Koerts
Wednesday, December 04, 2002

Real easy to solve this for future versions: please FogCreek, give us real scripting capabilities.  To not even have an If statement creates some real headaches.

Dan

Daniel Read
Wednesday, July 30, 2003

*  Recent Topics

*  Fog Creek Home